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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Werdinkaa
Frequent Visitor

DAX calculate difference between current and previous month - show values for all categories

Hi, 

I have a model in Power pivot one with so called Keys which is related to my main data (Category,Key,Date, Value)

I have a slicer with months and pivot table which shows Key and calculated values from main table. 

I need to show difference between selected month and previous month and I am using those measures

Total = sum(Main[Value])

PreviousMonthTotal = calculate([Total], previousmonth(Main[Date])

It works nice however I need to calculate difference between it and if specific key didnt exist in data for current month it should show previous one and the other way, if its not in current then still show key but with blank. 

 

Unfortunately it shows only keys which exist in month selected on slicer. 

if in pivot table I only show grouped values by category results are correct, but when I go to maximum granularity (key) it doesnt show me exact resutlts.

How can I force it to show in pivot table all keys from those two months?

1 REPLY 1
v-lid-msft
Community Support
Community Support

Hi @Werdinkaa ,

 

We can try to create a seprate dim table first. (keep no relationship with the main table)

 

CategoryTable = Distinct('Main'[Category])

 

Then replace the measure total as following to meet your requirement:

 

Total =
CALCULATE (
    SUM ( Main[Value] ),
    Main[Category] IN DISTINCT ( CategoryTable[Category] )
)

 

 

If it doesn't meet your requirement, kindly share your sample data and expected result to me if you don't have any Confidential Information. Please upload your files to OneDrive For Business and share the link here.


Best regards,

 

Community Support Team _ Dong Li
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Feb2025 NL Carousel

Fabric Community Update - February 2025

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