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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
bipowerbix
Helper I
Helper I

DAX Combinations not working as intended.

We have two tables 

 

Table A =  

 

 

Dates = CALENDAR(date(2023,1,1),TODAY())

 

 

Table B = 

Type        Cost   Return  Date

Apple100 1/1/2023
Orange502001/5/2023
Banana251502/1/2023
Pear 5002/22/2023
Kiwi  1/25/2023
Pear504001/5/2023

 

Relationship between columns:

bipowerbix_0-1680030604908.png

 

Date joined to Date from Data table, One to Many.

 

Example 1:

DAX to get ROI 

 

ROIZ = 
VAR V1 = CALCULATE(SUM(Data[Spent]),ALLSELECTED(Dates[Date]),ALLEXCEPT(Data,Data[Type]))
VAR V2 = CALCULATE(SUM(Data[Returns]),ALLSELECTED(Dates[Date]),ALLEXCEPT(Data,Data[Type]))
return divide(V2,V1,0)

 

 

When I select January, I get the following:

bipowerbix_0-1680030232640.png

which is wrong, pear should show 8 instead of 18, and Kiwi is missing.

 

When I select February, I get the following:

bipowerbix_0-1680030417796.png

 

which is wrong, pear should show nothing or 0

 

Expected Output: (January)

Type    Spent  Returns ROI     Date

Apple100 null      01/1/2023
Orange50 200      41/5/2023
Kiwinull null      01/25/2023
Pear50  400    81/5/2023
total200  600    6 

 

OR 

 

Expected Output February

Type     Spent   Return  ROI    Date

Banana   25 150    62/1/2023
Pear  null 500      02/22/2023
Total    25650       6 
3 REPLIES 3
bipowerbix
Helper I
Helper I

 

ROIZ = 
VAR V1 = CALCULATE(SUM(Data[Spent]),ALLSELECTED(Dates[Date]),ALLEXCEPT(Data,Data[Type]))
VAR V2 = CALCULATE(SUM(Data[Returns]),ALLSELECTED(Dates[Date]),ALLEXCEPT(Data,Data[Type]))
return divide(V2,V1,0) +0

 

Tried this to get Kiwi, however, the Pear shows the wrong amount, 18 instead of 8

bipowerbix_0-1680068661581.png

 

 

Greg_Deckler
Community Champion
Community Champion

@bipowerbix Ditch the CALCULATE statements, as in most cases, they are are not needed:

ROIZ NC = 
    VAR __V1 = SUM('Data'[Cost])
    VAR __V2 = SUM('Data'[Return])
    VAR __Result = DIVIDE(__V2, __V1)
RETURN
    __Result


Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...

Hi Greg, Thanks for the reply, Yes I was using Calculate() to Solve for Kiwi. Still don't see Kiwi in the result. I want to show the line items that don't have data as well, as shown in expected output

 

ROI9 = 
VAR V1 = SUM(Data[Spent])
VAR V2 = SUM(Data[Returns])
VAR V3 =  divide(V2,V1)
RETURN V3

 

bipowerbix_0-1680035589797.png

 

Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 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.