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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
anettbaksa
Frequent Visitor

Calculated measure with hierarchical data

Hello everybody, 

 

I have an issue with Previous year to date sales DAX calculation. 

Prev Yr YTD Sales/1M = CALCULATE(SUM('SALES VALUE'[VALUES]),DATESBETWEEN('SALES VALUE'[PERIOD],FIRSTDATE('SALES VALUE'[PERIOD]),[selected date]-365))
 

anettbaksa_0-1618152255514.png

In the picture, we can see the "selected date" column. This date column shows the last data delivery time and the Previous YTD sales calculation must adjust to this date. For example the calculated measure at "Instant noodles" subcategory has to show just 2020. January - this will be the previous YTD period. "Cook up" soup has to show 2020 January and February (However the date shows always the first day of the month these are whole month data, the delivery happens once a month). 

In Subcategory level my calculation works correctly but in Category level it's not working. This is logical because my calculation use "MAX" DAX expression and at Category level the max will be 2021.02.01. 

 

I need some tips how can I SUM the Subcategory level to Category level correctly. 

1 ACCEPTED SOLUTION
v-deddai1-msft
Community Support
Community Support

Hi @anettbaksa ,

 

Would you please try to use the following measure:

 

Prev Yr YTD Sales/1M =
SUMX (
    SUMMARIZE ( 'SALES VALUE', 'SALES VALUE'[CATEGORY], 'SALES VALUE'[SUNCATEGORY] ),
    CALCULATE (
        SUM ( 'SALES VALUE'[VALUES] ),
        DATESBETWEEN (
            'SALES VALUE'[PERIOD],
            FIRSTDATE ( 'SALES VALUE'[PERIOD] ),
            [selected date] - 365
        )
    )
)

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

View solution in original post

2 REPLIES 2
v-deddai1-msft
Community Support
Community Support

Hi @anettbaksa ,

 

Would you please try to use the following measure:

 

Prev Yr YTD Sales/1M =
SUMX (
    SUMMARIZE ( 'SALES VALUE', 'SALES VALUE'[CATEGORY], 'SALES VALUE'[SUNCATEGORY] ),
    CALCULATE (
        SUM ( 'SALES VALUE'[VALUES] ),
        DATESBETWEEN (
            'SALES VALUE'[PERIOD],
            FIRSTDATE ( 'SALES VALUE'[PERIOD] ),
            [selected date] - 365
        )
    )
)

 

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

 

Best Regards,

Dedmon Dai

daxer-almighty
Solution Sage
Solution Sage

@anettbaksa 

 

Before you start doing time calculations (the way you do), please read this first to see how to do it correctly: Standard time-related calculations – DAX Patterns

 

Also, please read this to see what it means to have a correct model in PBI.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.