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

Date-over-Date calculation dividing two measures breaks relationship (e.g. YoY, MoM, etc)

I have spent about 2 hours searching around trying to find a solution, but I couldn't find anyone having the same issue and for which the solution solved my problem.

The closest topics I've found where:

https://community.powerbi.com/t5/Desktop/Adding-a-simple-constant-valued-measure-stops-breaks/m-p/22...

https://community.powerbi.com/t5/Desktop/YoY-Change-Quick-Measure-Breaks-When-Filtered/m-p/1090040

First one created the constant in another table with no relationship to the previous two, and I've created all my measures inside one of my tables.

The second one seemed to have a problem with DATEADD, not with the relationship itself.

Now, to my dashboad and my issue:

I have two tables. The first one, 'product_data', has the revenue for each client. The other table, 'clients' has the account manager for each client and how we group them by company size.

'product_data' comes from an API

'clients' is filled manually. We get client_id from the 'product_data' report and Account Managers fill in their names for their clients.

flvon_2-1648755406683.png

 

People in my dashboard will select a "before" date in a slicer using 'dax_calendar' and that will define which date is the last one to do the calculations with. 'dax_calendar' is a calendar I created with DAX in this dashboard.

All the measures are being created in my 'product_data' table.

 

 

 

Revenue M-1 (#) = 
var shiftedDate = LASTDATE(DATEADD(dax_calendar[Date], -1, MONTH))
var shiftedMonth = MONTH(shiftedDate)
var shiftedYear = YEAR(shiftedDate)
return
CALCULATE(SUM(product_data[revenue]),
    MONTH(product_data[date]) = {shiftedMonth}, YEAR(product_data[date]) = {shiftedYear})
Revenue M-2 (#) = 
var shiftedDate = LASTDATE(DATEADD(dax_calendar[Date], -2, MONTH))
var shiftedMonth = MONTH(shiftedDate)
var shiftedYear = YEAR(shiftedDate)
return
CALCULATE(SUM(product_data[revenue]),
    MONTH(product_data[date]) = {shiftedMonth}, YEAR(product_data[date]) = {shiftedYear})

 

 

 

Example: if someone selects 2021-05-20 in the slicer, it'll calculate the revenue for March and April.

I also have other measures that calculate a to-date revenue, that's why I opted for using a "before" slicer and getting the last date selected there.

When I add a table using client_id from 'product_data' and these two measures I mentioned above, everything works fine.

But whenever I add this last measure to my table, it breaks the relationship, and each client_id in 'product_data' seems to get related to every client_id in 'clients'.

 

 

 

MoM Revenue (%) = DIVIDE(product_data[Revenue M-1 ($)], product_data[Revenue M-2 ($)],2)-1

 

 

 

Here's the visualization of what happens.

flvon_1-1648755366867.png

 

 

The last thing is: I want to add a filter to the whole dashboard using the 'group'. But because of all these duplications, every single client_id in my measure becomes a part of all groups, under all account managers and the filter becomes useless.

Things I've tried and/or realized:

  1. If it makes any difference, I created the relationship manually in a One:Many setup (from 'clients' to 'product_data'), but the relationship gets inverted to Many:One by Power BI automatically (from 'product_data' to 'clients')
  2. I first thought maybe DIVIDE was dividing empty values and because it has an alternate value built-in, it was going through. I've removed the DIVIDE and wrote the math directly but it didn't change anything.
  3. Filtering for "revenue > 0" doesn't work. Account Managers can select different dates and one thing I want to have explicit in the dashboard are the clients who have zero revenue at some point.
  4. Using the column client_id from the clients table instead of from 'product_data' solves the issue, but the thing is: the clients table is delayed compared to product_data because we fill it manually, so I want to show the ID coming from the table product_data.
  5. I've been searching for a way to only do the division and show values when both client_id's are the same in both tables, but found nothing.

 

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

From what I am understanding, here's my solution.

1.Create a calendar. If you have a calendar table yourself, you can use it directly.

Calendar = CALENDAR(MIN('revenue'[date]),MAX('revenue'[date]))

The relationships are as follows.

vstephenmsft_0-1651646270884.png

 

2.Revenue M-1 and Revenue M-2 are as follows.

Revenue M-1 = 
var _date=SELECTEDVALUE('Calendar'[Date])
var _end=EOMONTH(_date,-1)
var _start=EOMONTH(_date,-2)+1
return  CALCULATE(SUM(revenue[revenue]),FILTER('revenue',[date]>=_start&&[date]<=_end))
Revenue M-2 = 
var _date=SELECTEDVALUE('Calendar'[Date])
var _end=EOMONTH(_date,-2)
var _start=EOMONTH(_date,-3)+1
return  CALCULATE(SUM(revenue[revenue]),FILTER('revenue',[date]>=_start&&[date]<=_end))

Then you can calculate the MoM.

MoM = DIVIDE([Revenue M-1]-[Revenue M-2],[Revenue M-2])

 

3.The dates in the slicer are from the calendar table. For example, when you select '4/28/2021', the result is as follows.

vstephenmsft_1-1651646406040.png

 

Best Regards,

Stephen Tao

 

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

4 REPLIES 4
Anonymous
Not applicable

Here's sample data:

Table with revenue per client, which is also the table where all the measures are being created:

client_iddaterevenue
101/01/202110
101/02/202120
101/03/202130
101/04/202140
101/05/202150
101/06/202160
201/01/202170
201/02/202180
201/03/202190
201/04/2021100
201/05/2021110
201/06/2021120
301/01/2021130
301/02/2021140
301/03/2021150
301/04/2021160
301/05/2021170
301/06/2021180
401/01/2021190
401/02/2021200
401/03/2021210
401/04/2021220
401/05/2021230
401/06/2021240
501/01/2021250
501/02/2021260
501/03/2021270
501/04/2021280
501/05/2021290
501/06/2021300

Table with clients and their respective account managers:

client_idacc_managerclient_group
1John JoeStrategic
2Jane JoeStrategic
3Jack JayCorporate
4Mary MooreCorporate
5Louis LatoMedium
6Lianna LisaMedium


Here's the actual outcome whenever I add only the absolute revenue values (which is the expected result):

client_idacc_managerclient_groupRevenue M-1Revenue M-2
1John JoeStrategic3020
2Jane JoeStrategic9080
3Jack JayCorporate150140
4Mary MooreCorporate210200
5Louis LatoMedium270260
6Lianna LisaMedium00

 

Here's the actual outcome whenever I add the MoM variation using client_id from the revenue table:

client_idacc_managerclient_groupRevenue M-1Revenue M-2MoM
1John JoeStrategic302050,0%
1Jane JoeStrategic00-100,0%
1Jack JayCorporate00-100,0%
1Mary MooreCorporate00-100,0%
1Louis LatoMedium00-100,0%
2John JoeStrategic00-100,0%
2Jane JoeStrategic908012,5%
2Jack JayCorporate00-100,0%
2Mary MooreCorporate00-100,0%
2Louis LatoMedium00-100,0%
3John JoeStrategic00-100,0%
3Jane JoeStrategic00-100,0%
3Jack JayCorporate1501407,1%
3Mary MooreCorporate00-100,0%
3Louis LatoMedium00-100,0%
4John JoeStrategic00-100,0%
4Jane JoeStrategic00-100,0%
4Jack JayCorporate00-100,0%
4Mary MooreCorporate2102005,0%
4Louis LatoMedium00-100,0%
5John JoeStrategic00-100,0%
5Jane JoeStrategic00-100,0%
5Jack JayCorporate00-100,0%
5Mary MooreCorporate00-100,0%
5Louis LatoMedium2702603,8%


Here's the outcome I'm looking for when adding the MoM variations:

client_idacc_managerclient_groupRevenue M-1Revenue M-2MoM
1John JoeStrategic302050,0%
2Jane JoeStrategic908012,5%
3Jack JayCorporate1501407,1%
4Mary MooreCorporate2102005,0%
5Louis LatoMedium2702603,8%
6Lianna LisaMedium00-100,0%

 

Anonymous
Not applicable

Hi @Anonymous ,

 

From what I am understanding, here's my solution.

1.Create a calendar. If you have a calendar table yourself, you can use it directly.

Calendar = CALENDAR(MIN('revenue'[date]),MAX('revenue'[date]))

The relationships are as follows.

vstephenmsft_0-1651646270884.png

 

2.Revenue M-1 and Revenue M-2 are as follows.

Revenue M-1 = 
var _date=SELECTEDVALUE('Calendar'[Date])
var _end=EOMONTH(_date,-1)
var _start=EOMONTH(_date,-2)+1
return  CALCULATE(SUM(revenue[revenue]),FILTER('revenue',[date]>=_start&&[date]<=_end))
Revenue M-2 = 
var _date=SELECTEDVALUE('Calendar'[Date])
var _end=EOMONTH(_date,-2)
var _start=EOMONTH(_date,-3)+1
return  CALCULATE(SUM(revenue[revenue]),FILTER('revenue',[date]>=_start&&[date]<=_end))

Then you can calculate the MoM.

MoM = DIVIDE([Revenue M-1]-[Revenue M-2],[Revenue M-2])

 

3.The dates in the slicer are from the calendar table. For example, when you select '4/28/2021', the result is as follows.

vstephenmsft_1-1651646406040.png

 

Best Regards,

Stephen Tao

 

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

 

Your samples lead me to assume that this is filtered to April 2021?

lbendlin
Super User
Super User

Please provide sanitized sample data that fully covers your issue. If you paste the data into a table in your post or use one of the file services it will be easier to assist you. Avoid posting screenshots of your source data if possible.

Please show the expected outcome based on the sample data you provided. Screenshots of the expected outcome are ok.

https://community.powerbi.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447523

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!

November Power BI Update Carousel

Power BI Monthly Update - November 2025

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

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.