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
thenerv25
Frequent Visitor

Inaccurate data with calculate function

I have a calculated column (YTD Revenue) that is displaying accurate totals (when compared to the source file), but the line level detail (when displaying with another attribute in the same table) is significantly off. The Revenue column in the belowsnippet is just the raw revenue column from the fact table and it matches what is in the source data (at the line level and in total). Customer number is not a dim, it is just an attribute on that same fact table that has the raw revenue field. I've included my YTD revenue calculation below the image. 

 

When i export this table and do a sum in excel, the PA YTD revenue column actually sums up to 638k (more than 10% above the accurate total of 561k), yet it displays here as 561k. You can see some of the rows that are different in the image below. I have filtered the data just on this most recent month to simplify the initial analysis. So while all months are similarly off, this is obviously just showing October.

 

Has anyone seen this behavior with the calculate columns and/or figured out a solution for the root cause? Thank you so much for the help, this has been a big challenge for weeks and is preventing us from being able to drill down accurately!

 

thenerv25_0-1605012696578.png

 

PA YTD Revenue =
var MonthsToDate = Month([PA Max Invoice Date])
var currentYear = Year([PA Max Invoice Date] )
//Max invoice date will always be the end of the most recently loaded month
var Revenue =
CALCULATE(
[PA Total Revenue]
,'DIM Date'[Month of Year] <= MonthsToDate
,'DIM Date'[Year] = currentYear
)
 
return Revenue
1 ACCEPTED SOLUTION
thenerv25
Frequent Visitor

@v-yingjl thank you for taking a stab at this. Unfortunately Power BI wouldn't take the syntax of .Month or .Year.

The good news is that I have figured this out. In case anyone else ever runs into an issue like this, below is the summary.

I had understood max(invoice date) to be taking the maximum invoice date of the full data set and applying that 1 date value to all records in a table that would be displaying that measure. What I realized is that the max(invoice date) is actually separately evaluating each row/record in the table (i.e. taking the maximum invoice date for each row) which yields very different results, and tables where the totals (the only place that actually does use the full data set value) will not match the sum of the table. 

View solution in original post

4 REPLIES 4
thenerv25
Frequent Visitor

@v-yingjl thank you for taking a stab at this. Unfortunately Power BI wouldn't take the syntax of .Month or .Year.

The good news is that I have figured this out. In case anyone else ever runs into an issue like this, below is the summary.

I had understood max(invoice date) to be taking the maximum invoice date of the full data set and applying that 1 date value to all records in a table that would be displaying that measure. What I realized is that the max(invoice date) is actually separately evaluating each row/record in the table (i.e. taking the maximum invoice date for each row) which yields very different results, and tables where the totals (the only place that actually does use the full data set value) will not match the sum of the table. 

Hi @thenerv25 ,

Glad to hear the issue is solved. You can accept your reply as solution, that way, other community members could easily find the answer when they get same issues.


Best Regards,
Community Support Team _ Yingjie Li


thenerv25
Frequent Visitor

I've done some further troubleshooting on this and have narrowed it down to something very odd that I thought I would throw out there in case it triggered something for someone. 

 

When looking at the formula below, if i hard code the month (e.g. 10), it works perfectly fine. When I leave it dynamically pulled, i get the issue described above. I have quadruple checked that the dynamic value (month([PA Max Invoice Date]) is as expected and also confirmed that hard coded and dynamically pulled have the same data type (20). Any tips or clues as to what might be going on would be greatly appreciated!

Hi @thenerv25 ,

Try to modify the formula like this:

PA YTD Revenue =
VAR MonthsToDate = [PA Max Invoice Date].MONTH
VAR currentYear = [PA Max Invoice Date].YEAR //Max invoice date will always be the end of the most recently loaded month
VAR Revenue =
    CALCULATE (
        [PA Total Revenue],
        'DIM Date'[Month of Year] <= MonthsToDate,
        'DIM Date'[Year] = currentYear
    )
RETURN
    Revenue

If not work, could you please consider sharing a sample file without sesentive information for further discussion?

 

Best Regards,
Community Support Team _ Yingjie 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
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.