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

To celebrate FabCon Vienna, we are offering 50% off select exams. Ends October 3rd. Request your discount now.

Reply
Sekhar1
Frequent Visitor

Unable to calculated difference using DAX

Hi, 

I am getting error while trying to calculate difference between weeks. Please see below sample table 

 

YearYear and Week NoQuarterQuarterInYearTotalsDate
20222022_WK07Q1Q1 202233331-Mar-22
20232023_WK07Q1Q1 20231,34431-Mar-23
20222022_WK07Q1Q1 20225,15131-Mar-22
20232023_WK07Q1Q1 202360031-Mar-23
20222022_WK07Q1Q1 202250031-Mar-22
20232023_WK07Q1Q1 202387431-Mar-23
20222022_WK07Q1Q1 202216,16131-Mar-22
20232023_WK07Q1Q1 202315,15131-Mar-23
20222022_WK07Q1Q1 2022211,64631-Mar-22
20222022_WK07Q1Q1 202251,56131-Mar-22
20222022_WK07Q1Q1 20225131-Mar-22
20222022_WK07Q1Q1 20225,15131-Mar-22
20222022_WK07Q1Q1 202251,85831-Mar-22
20222022_WK07Q1Q1 20227,89431-Mar-22
20222022_WK07Q1Q1 20221,46331-Mar-22
20232023_WK07Q1Q1 20231,58231-Mar-23
20232023_WK07Q1Q1 20232,45331-Mar-23
20232023_WK07Q1Q1 20233,58631-Mar-23
20232023_WK07Q1Q1 20236,58931-Mar-23
20232023_WK07Q1Q1 202359,67431-Mar-23
20232023_WK07Q1Q1 202336,54131-Mar-23

 

Year, Year and Week No  filters table below it.

Year 2, Year and Week No 2 filters table below it. 

I wanted to calculate difference based on user selection of filters and not getting any difference. 

 

Sekhar1_0-1687163581736.png

I have used following DAX:- 

 
Difference =
VAR YearTotal =
    CALCULATE (
        SUM ( 'Table'[Totals] ),
            REMOVEFILTERS('Calendar Table 2'[Year]),
           REMOVEFILTERS ('Table'[Year and Week No 2]))
VAR PYearTotal =
    CALCULATE (
        SUM ( 'Table'[Totals] ),
            REMOVEFILTERS('Calendar Table'[Year]),
           REMOVEFILTERS ('Table'[Year and Week No]))

 

VAR Result = YearTotal - PYearTotal
Return
Result 
 
Can you please have a look and let me know where the error is. 
 
Thanks in advance for help. 
 
1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Sekhar1 ,

 

According to your statement, I think the relationship between the column will cause this issue.I suggest you to create two unrelated slicer tables with [Year] and [Year and Week No] columns you need.

Data model:

vrzhoumsft_0-1687338733852.png

Measures:

Sum of Total 1 = 
 CALCULATE(SUM('Table'[Totals]),USERELATIONSHIP('DimDate 1'[Date],'Table'[Date]))
Sum of Total 2 = 
 CALCULATE(SUM('Table'[Totals]),USERELATIONSHIP('DimDate 2'[Date],'Table'[Date]))
Difference = 
[Sum of Total 1] - [Sum of Total 2]

 Result is as below.

vrzhoumsft_1-1687338785323.png

 

Best Regards,
Rico Zhou

 

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

View solution in original post

2 REPLIES 2
Anonymous
Not applicable

Hi @Sekhar1 ,

 

According to your statement, I think the relationship between the column will cause this issue.I suggest you to create two unrelated slicer tables with [Year] and [Year and Week No] columns you need.

Data model:

vrzhoumsft_0-1687338733852.png

Measures:

Sum of Total 1 = 
 CALCULATE(SUM('Table'[Totals]),USERELATIONSHIP('DimDate 1'[Date],'Table'[Date]))
Sum of Total 2 = 
 CALCULATE(SUM('Table'[Totals]),USERELATIONSHIP('DimDate 2'[Date],'Table'[Date]))
Difference = 
[Sum of Total 1] - [Sum of Total 2]

 Result is as below.

vrzhoumsft_1-1687338785323.png

 

Best Regards,
Rico Zhou

 

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

amitchandak
Super User
Super User

@Sekhar1 , iof you want to use two date slicers, refer these ways

Power BI Abstract Thesis: How to use two Date/Period slicers

https://youtu.be/WSeZr_-MiTg

 

For Week on Week

 

Power BI — Week on Week and WTD
https://medium.com/@amitchandak.1978/power-bi-wtd-questions-time-intelligence-4-5-98c30fab69d3
https://community.powerbi.com/t5/Community-Blog/Week-Is-Not-So-Weak-WTD-Last-WTD-and-This-Week-vs-La...
https://www.youtube.com/watch?v=pnAesWxYgJ8
Time Intelligence, Part of learn Power BI https://youtu.be/cN8AO3_vmlY?t=27510

Share with Power BI Enthusiasts: Full Power BI Video (20 Hours) YouTube
Microsoft Fabric Series 60+ Videos YouTube
Microsoft Fabric Hindi End to End YouTube

Helpful resources

Announcements
September Power BI Update Carousel

Power BI Monthly Update - September 2025

Check out the September 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Solution Authors