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

HASONEVALUE across 2 time periods

Hi, I'm still new to PowerBI and still learning how to write measures.
Currently I'm unable to get my grand totals to work.  I have tried using HASONEVALUE but because it is comparing 2 time periods the way I'm writing it doesn't seem to work.  
 
I have the following calculations (where CY = current year, LY = last year) at customer level:
 
Diff to LY TotalSales = TotalSales CY - TotalSales LY  
Value = IF (ISBLANK([TotalSales LY]), BLANK(), (([Price CY] - [Price LY]) * [Units CY Total]))
Volume = [Diff to LY TotalSales] - [Value]
 
The Volume column is calculating correctly at row level ie customer level however the grand total at the bottom of the column is not correct.
So I then tried to use the HASONEVALUE function but it doesn't work in the case where a customer was present last year but is not present this year.  How do I get the grand total to work?  This is the measure I tried to write.
 
Volume by Customer = if (HASONEVALUE(Table 1[ContactGenericName]), [Volume],
SUMX( VALUES(Table 1[ContactGenericName]),[Volume]))
 
The table looks like this: 
Pic.JPG
 
Hope this is an easy question for someone. Many thanks.
2 REPLIES 2
YJ
Resolver II
Resolver II

Can you provide the pbix file, if you need to mask out any sensentive info

regards

SonyT
Frequent Visitor

Hi, 

 

Sorry, it's an enormous file with too much info to remove.

 

Can I provide you with something else to help?

 

Thank you.

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.