Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now! Learn more

Reply
Anonymous
Not applicable

DAX to measure Same Store Sale

Hello everyone!

I am having trouble writing a DAX formula in Power BI to calculate Same Store Sales (SSS). My calculation of SSS is (CURRENT_VALUE_ / PREVIOUS_VALUE_) - 1.

The problem is that, when looking at the CLIENT_ID hierarchy in a matrix visual in Power BI, I want the SSS measure to consider only the CURRENT_VALUE_ of the brands that also had sales in PREVIOUS_VALUE_.

For example, in the figure below, I want CLIENT_ID 123456 to show me an SSS of 27% in total, instead of 100%. That is, I want it to consider (140 / 110) - 1, instead of (220 / 110) - 1, as it should only sum the CURRENT_VALUE_ of the brands that also have PREVIOUS_VALUE_ (that is, only the GREEN and PINK brands).
Captura de tela 2024-06-28 165018.png




My current DAX formula is as follows:

VAR tempTable = SUMMARIZE(clients, clients[CLIENT_ID], "PER_ATUAL", [CURRENT_VALUE_] ,"PER_ANTER", [PREVIOUS_VALUE_])
VAR currentValue = SUMX(FILTER(tempTable, NOT ISBLANK([PER_ATUAL]) && NOT ISBLANK([PER_ANTER])), [PER_ATUAL])
VAR previousValue = SUMX(FILTER(tempTable, NOT ISBLANK([PER_ATUAL]) && NOT ISBLANK([PER_ANTER])), [PER_ANTER])

RETURN
IF(DIVIDE(currentValue, previousValue, BLANK()) -1 = -1 ,
BLANK(),
DIVIDE(currentValue, previousValue, BLANK()) -1
)

Any help or tips?

 

1 ACCEPTED SOLUTION
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how you semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1719649226014.png

 

 

Jihwan_Kim_0-1719649203562.png

 

Current sales: = 
SUM( sales[sales] )

 

Previous sales: = 
CALCULATE (
    [Current sales:],
    OFFSET ( -1, ALL ( 'year'[year] ), ORDERBY ( 'year'[year], ASC ) )
)

 

Expected result measure: = 
VAR _t =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( sales, client[client_id], store[store_id], 'year'[year] ),
            "@current", [Current sales:],
            "@prev", [Previous sales:]
        ),
        NOT ISBLANK ( [@prev] )
    )
VAR _result =
    DIVIDE ( SUMX ( _t, [@current] ), SUMX ( _t, [@prev] ) ) - 1
RETURN
    IF ( NOT ISBLANK ( [Previous sales:] ), _result )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.

View solution in original post

2 REPLIES 2
Jihwan_Kim
Super User
Super User

Hi,

I am not sure how you semantic model looks like, but I tried to create a sample pbix file like below.

Please check the below picture and the attached pbix file.

 

Jihwan_Kim_1-1719649226014.png

 

 

Jihwan_Kim_0-1719649203562.png

 

Current sales: = 
SUM( sales[sales] )

 

Previous sales: = 
CALCULATE (
    [Current sales:],
    OFFSET ( -1, ALL ( 'year'[year] ), ORDERBY ( 'year'[year], ASC ) )
)

 

Expected result measure: = 
VAR _t =
    FILTER (
        ADDCOLUMNS (
            SUMMARIZE ( sales, client[client_id], store[store_id], 'year'[year] ),
            "@current", [Current sales:],
            "@prev", [Previous sales:]
        ),
        NOT ISBLANK ( [@prev] )
    )
VAR _result =
    DIVIDE ( SUMX ( _t, [@current] ), SUMX ( _t, [@prev] ) ) - 1
RETURN
    IF ( NOT ISBLANK ( [Previous sales:] ), _result )

 


If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Click here to visit my LinkedIn page

Click here to schedule a short Teams meeting to discuss your question.
Anonymous
Not applicable

It worked perfectly. Thank you so much!!

Helpful resources

Announcements
Power BI DataViz World Championships

Power BI Dataviz World Championships

The Power BI Data Visualization World Championships is back! Get ahead of the game and start preparing now!

December 2025 Power BI Update Carousel

Power BI Monthly Update - December 2025

Check out the December 2025 Power BI Holiday Recap!

FabCon Atlanta 2026 carousel

FabCon Atlanta 2026

Join us at FabCon Atlanta, March 16-20, for the ultimate Fabric, Power BI, AI and SQL community-led event. Save $200 with code FABCOMM.