• Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy
Wednesday, March 25, 2026
newsaiworld
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us
No Result
View All Result
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us
No Result
View All Result
Morning News
No Result
View All Result
Home Machine Learning

Following Up on Like-for-Like for Shops: Dealing with PY

Admin by Admin
March 25, 2026
in Machine Learning
0
Luke galloway 3s3c4qgrwa8 unsplash.jpg
0
SHARES
0
VIEWS
Share on FacebookShare on Twitter


Introduction

to my final article, about constructing the Like-for-Like (L4L) answer primarily based on Energy Question:

The answer works as anticipated for essentially the most half. I confirmed it to my friends and to some purchasers.

The suggestions was constructive, however I’ve bought some questions, and the outcomes of my answer weren’t what the individual asking anticipated.

READ ALSO

Manufacturing-Prepared LLM Brokers: A Complete Framework for Offline Analysis

Agentic RAG Failure Modes: Retrieval Thrash, Software Storms, and Context Bloat (and Find out how to Spot Them Early)

The problem

I found a difficulty whereas calculating the PY worth.

Technically, the outcomes are appropriate, however they aren’t from a consumer perspective.

Have a look at the next two screenshots, which present two completely different circumstances that embody the Retail Gross sales and the Retail Gross sales PY measures. The outcomes for these two circumstances can confuse the viewers.

Attempt to spot the problem earlier than persevering with to learn.

Determine 1 – The primary PY Case – Briefly closed (Refresh) retailer (Determine by the Creator)

That is the primary case for the Torino retailer, which was quickly closed between March and July 2024.

Determine 2- The second PY case – A mixture between a quickly closed and a Closing retailer (Determine by the Creator)

And right here is the second case for the Roma retailer, which was quickly closed from August to October 2023 and completely closed in August 2024.

We see these outcomes for the second case:

  1. The values for the Retail Gross sales PY measure for “Comparable” shops, however with an interruption between August and October.
  2. Values for the Retail Gross sales measure for “Non-Comparable – Closing” shops.
  3. Values for the Retail Gross sales PY measure for “Non-Comparable – Refresh” shops.

From a technical standpoint, these outcomes make absolute sense and are appropriate.

The measures present the right L4L States for the present interval and the earlier yr.

So, what are the problems?

For the consumer, they’re very complicated and won’t match expectations.

Give it some thought from the consumer’s perspective:

When taking a look at outcomes for particular L4L states, the 2 measures ought to assign outcomes to the identical L4L state, no matter whether or not they’re calculated for the present interval or the earlier yr.

This introduces a brand new complexity to the answer.

The answer

I would like a second column for the L4LKey for the earlier yr.

For the primary L4LKey column, I examine the opening and shutting dates to the month-to-month dates of the earlier yr (See the primary article for the small print).

For the second L4LKey_PY column, I need to examine these dates to the month-to-month dates of the identical yr because the opening and closure dates.

The thought is considerably counterintuitive, however it delivers the consequence I would like.
Please stick with me, and you will notice the way it pans out

First, I attempted fixing it in Energy Question, as I did within the authentic answer. Nevertheless it didn’t work. I’ll come to the explanation in a minute.

Then, I switched to constructing the Bridge_L4L desk in SQL, however the outcomes have been unusable once more, as I at all times bought duplicated rows for the Rome retailer, as I’ve two rows for the 2 L4L-states for this retailer:

Determine 3 – Two rows for the Rome retailer (ID 222) for the 2 years 2023 and 2024 (Determine by the Creator)

I’ve one row every for the momentary closure in 2023 and the definitive closure in 2024.

Due to this fact, the be part of at all times returns two rows, as the shop secret is duplicated.

So, I made a decision to change to a procedural strategy.

I loop via every row within the desk containing the opening and shutting shops and apply the states to the desk, which has one row per retailer and month.

I did this through the use of momentary tables in SQL and the next SQL code:

-- Declare all wanted variables
DECLARE @StoreKey       int;
DECLARE @OpenDate       date;
DECLARE @CloseDate      date;
DECLARE @L4LKey         int;

-- Create the Cursor to loop via the Shops with every opening, closing, and refresh dates
DECLARE sd CURSOR FOR
    SELECT [StoreKey]
            ,[OpenDate]
            ,[CloseDate]
            ,[L4LKey]
        FROM #tmp_Store_Dates
            -- Order per Cut-off date, because the process should run from the primary (oldest) to the final (latest) row
            ORDER BY [CloseDate];

OPEN sd;

-- Get the primary row
FETCH NEXT FROM sd INTO @StoreKey, @OpenDate, @CloseDate, @L4LKey;

-- Begin the loop
WHILE @@FETCH_STATUS = 0
BEGIN
    -- Replace all rows based on every retailer primarily based on the L4L standing and the respective dates, primarily based on the earlier years' dates
    UPDATE [#tmp_Stores_Months]
        SET [OpenDate] = @OpenDate
            ,[CloseDate] = @CloseDate
            ,[L4LKey] = CASE @L4LKey
                            WHEN 2
                                THEN IIF(@OpenDate >= [FirstDayOfMonthPY], @L4LKey, NULL)
                            WHEN 3
                                THEN IIF(@CloseDate <= [LastDayOfMonthPY], @L4LKey, NULL)
                            WHEN 4
                                THEN IIF(@OpenDate >= [FirstDayOfMonthPY] AND @CloseDate <= [LastDayOfMonthPY], @L4LKey, NULL)
                                ELSE 1
                            END
            WHERE [L4LKey] IS NULL
                AND [StoreKey] = @StoreKey;

-- Replace primarily based on the identical month for the PY calculation
UPDATE [#tmp_Stores_Months]
        SET [OpenDate] = @OpenDate
            ,[CloseDate] = @CloseDate
            ,[L4LKey_PY] = CASE @L4LKey
                            WHEN 2
                                THEN IIF(@OpenDate >= [FirstDayOfMonth], @L4LKey, NULL)
                            WHEN 3
                                THEN IIF(@CloseDate <= [LastDayOfMonth], @L4LKey, NULL)
                            WHEN 4
                                THEN IIF(@OpenDate >= [FirstDayOfMonth] AND @CloseDate <= [LastDayOfMonth], @L4LKey, NULL)
                                ELSE 1
                            END
            WHERE [L4LKey_PY] IS NULL
                AND [StoreKey] = @StoreKey;
    
    -- Get the following row till all rows are processed
    FETCH NEXT FROM sd INTO @StoreKey, @OpenDate, @CloseDate, @L4LKey;

END

-- Shut the Cursor
CLOSE sd;
DEALLOCATE sd;

-- Replace the L4LKey and L4LKey_PY in all empty rows
UPDATE #tmp_Stores_Months
    SET [L4LKey] = 1
        WHERE [L4LKey] IS NULL;

UPDATE #tmp_Stores_Months
    SET [L4LKey_PY] = 1
        WHERE [L4LKey_PY] IS NULL;

The results of the process is a desk containing one column mapping the L4L states primarily based on the earlier yr for every month (L4LKey) and one column mapping the L4L states primarily based on the identical yr for every month (L4LKey_PY):

Determine 4 – The results of the process for the Bridge_L4L desk with the 2 L4LKey columns (Determine by the Creator)

The following step is to import the consequence for this process into Energy BI and add an extra relationship between the Bridge_4L and the DIM_L4L desk for the brand new L4LKey_PY column:

Determine 5 – The datamodel with the extra L4LKey_PY column and the extra relationship to DIM_L4L (Determine by the Creator)

This permits me to regulate the calculation for the PY consequence.

Retail Gross sales (PY) =
CALCULATE([Retail Sales]
            ,'Time Intelligence'[Time Measures] = "PY"
            ,USERELATIONSHIP('Bridge_L4L'[L4LKey_PY], 'DIM_L4L'[L4LKey])
            )

Now, the outcomes are what is predicted.

Right here, the primary case:

Determine 6 – The outcomes for the Rome retailer for 2024. Now the outcomes are constant (Determine by the Creator)

And listed below are the outcomes for the second case:

Determine 7 – The constant outcomes for the shop for 2025 (Determine by the Creator)

As you possibly can see, the PY values are assigned to the identical L4L state because the current-year outcomes.

Now, the consumer sees constant outcomes, that are a lot simpler to grasp.

Conclusion

The extra name of the USERELATIONSHIP() perform could be put in a Calculation Merchandise and utilized by all PY measures.

This makes it very simple to make use of with none further DAX logic.

Anyway, this problem was comparatively simple to unravel. However after I thought of a Month-over-Month calculation with the L4L performance, I noticed it wouldn’t be doable with out some DAX code. Probably, I’ll dig into this in a future article.

However this case emphasizes the necessity to use the consumer’s perspective when designing and testing an answer.

It isn’t sufficient to make use of a technical perspective; the consumer’s perspective is rather more vital when evaluating the answer’s performance and outcomes.

For me, this was a really attention-grabbing expertise and really helpful for my future work.

I hope that you simply discover my strategy attention-grabbing. Keep tuned for my subsequent piece.

References

That is my earlier article on this matter:

Right here is the SQLBI article concerning the like-for-like sample with a DAX answer primarily based on model-independent UDFs.

Like in my earlier articles, I exploit the Contoso pattern dataset. You may obtain the ContosoRetailDW Dataset free of charge from Microsoft right here.

The Contoso Information can be utilized freely underneath the MIT License, as described on this doc. I up to date the dataset to shift the info to modern dates and eliminated all tables not wanted for this instance.

Tags: HandlingLikeforLikeStores

Related Posts

Featureimage llmagent offlineevaluaation 1.jpg
Machine Learning

Manufacturing-Prepared LLM Brokers: A Complete Framework for Offline Analysis

March 24, 2026
Image 217 1.jpg
Machine Learning

Agentic RAG Failure Modes: Retrieval Thrash, Software Storms, and Context Bloat (and Find out how to Spot Them Early)

March 23, 2026
Daniel von appen gnxepl wzfg unsplash scaled 1.jpg
Machine Learning

A Light Introduction to Nonlinear Constrained Optimization with Piecewise Linear Approximations

March 22, 2026
Image 252.png
Machine Learning

The Math That’s Killing Your AI Agent

March 21, 2026
Skarmavbild 2026 03 16 kl. 20.16.38.jpg
Machine Learning

The Fundamentals of Vibe Engineering

March 19, 2026
Head img.png
Machine Learning

Two-Stage Hurdle Fashions: Predicting Zero-Inflated Outcomes

March 18, 2026
Next Post
Wolf of all streets 800x419.jpg

Mark Yusko: The Readability Act serves regulatory seize, banks profit from stablecoin settlements, and the crypto business should adapt politically

Leave a Reply Cancel reply

Your email address will not be published. Required fields are marked *

POPULAR NEWS

Gemini 2.0 Fash Vs Gpt 4o.webp.webp

Gemini 2.0 Flash vs GPT 4o: Which is Higher?

January 19, 2025
Chainlink Link And Cardano Ada Dominate The Crypto Coin Development Chart.jpg

Chainlink’s Run to $20 Beneficial properties Steam Amid LINK Taking the Helm because the High Creating DeFi Challenge ⋆ ZyCrypto

May 17, 2025
Image 100 1024x683.png

Easy methods to Use LLMs for Highly effective Computerized Evaluations

August 13, 2025
Blog.png

XMN is accessible for buying and selling!

October 10, 2025
0 3.png

College endowments be a part of crypto rush, boosting meme cash like Meme Index

February 10, 2025

EDITOR'S PICK

Ai Journal Overview 1.png

Learn how to Construct an AI Journal with LlamaIndex

May 16, 2025
Cloud essentials.jpg

A Newbie’s Information to CompTIA Cloud Necessities+ Certification (CLO-002)

September 12, 2025
Ai race and dataset level scaled.png

Why the AI Race Is Being Determined on the Dataset Stage

September 17, 2025
Img 1f3fmz1noinroyor1c9xv3qg 800x457.jpg

US Bitcoin ETFs see largest single-day influx since late July, Bitcoin climbs previous $60,000

September 15, 2024

About Us

Welcome to News AI World, your go-to source for the latest in artificial intelligence news and developments. Our mission is to deliver comprehensive and insightful coverage of the rapidly evolving AI landscape, keeping you informed about breakthroughs, trends, and the transformative impact of AI technologies across industries.

Categories

  • Artificial Intelligence
  • ChatGPT
  • Crypto Coins
  • Data Science
  • Machine Learning

Recent Posts

  • Mark Yusko: The Readability Act serves regulatory seize, banks profit from stablecoin settlements, and the crypto business should adapt politically
  • Following Up on Like-for-Like for Shops: Dealing with PY
  • 5 Helpful DIY Python Features for Error Dealing with
  • Home
  • About Us
  • Contact Us
  • Disclaimer
  • Privacy Policy

© 2024 Newsaiworld.com. All rights reserved.

No Result
View All Result
  • Home
  • Artificial Intelligence
  • ChatGPT
  • Data Science
  • Machine Learning
  • Crypto Coins
  • Contact Us

© 2024 Newsaiworld.com. All rights reserved.

Are you sure want to unlock this post?
Unlock left : 0
Are you sure want to cancel subscription?