Microsoft Fabric Community Conference 2025, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount.
Register nowThe Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.
Hi,
I am trying to calculate the difference between 2 values from 2 different tables. The data model consists of 3 tables and 5 dimension tables. The 2 tables that have the columns does not have a direct relationship between them. I want the subtraction to take place only when there is a value in the 2 columns. Also, I want to have the total value of this measure.
The following screenshot presents the tables and the current measures that I managed to produce (not functioning well!!). I want the card to show 1140. It is showing the same number as the value in the second table which is the sum of the values of 'Value 1' in that table minus the sum of values in the 'Value 2'.
Here is the dax for the measure on the card:
Solved! Go to Solution.
Hi, @Anonymous
Hope the following formula could work.
Variance (Value 1 - Value 2) =
VAR tab =
CROSSJOIN ( 'D:Location', 'D:Date' )
VAR tab2 =
FILTER (
ADDCOLUMNS (
tab,
"v1",
CALCULATE (
SUM ( 'F: Forecasted Data'[Value 1] ),
FILTER (
tab,
[Date] = EARLIER ( 'D:Date'[Date] )
&& [sheetName] = EARLIER ( 'D:Location'[sheetName] )
)
),
"v2",
CALCULATE (
SUM ( 'F: Confirmed Data'[Value 2] ),
FILTER (
tab,
[Date] = EARLIER ( 'D:Date'[Date] )
&& [sheetName] = EARLIER ( 'D:Location'[sheetName] )
)
)
),
[v1] <> BLANK ()
&& [v2] <> BLANK ()
)
RETURN
SUMX ( tab2, [v1] - [v2] )
Best Regards,
Community Support Team _ Eason
@Anonymous , Try return like
return
sumx(summarize('F: Forecasted Data', 'D: Location' [location], Date[Date], "_1", IF(NOT ISBLANK(__MEASURE_VALUE) && NOT ISBLANK(__BASELINE_VALUE), __BASELINE_VALUE - __MEASURE_VALUE )), [_1])
Hi, @Anonymous
Hope the following formula could work.
Variance (Value 1 - Value 2) =
VAR tab =
CROSSJOIN ( 'D:Location', 'D:Date' )
VAR tab2 =
FILTER (
ADDCOLUMNS (
tab,
"v1",
CALCULATE (
SUM ( 'F: Forecasted Data'[Value 1] ),
FILTER (
tab,
[Date] = EARLIER ( 'D:Date'[Date] )
&& [sheetName] = EARLIER ( 'D:Location'[sheetName] )
)
),
"v2",
CALCULATE (
SUM ( 'F: Confirmed Data'[Value 2] ),
FILTER (
tab,
[Date] = EARLIER ( 'D:Date'[Date] )
&& [sheetName] = EARLIER ( 'D:Location'[sheetName] )
)
)
),
[v1] <> BLANK ()
&& [v2] <> BLANK ()
)
RETURN
SUMX ( tab2, [v1] - [v2] )
Best Regards,
Community Support Team _ Eason
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
If you love stickers, then you will definitely want to check out our Community Sticker Challenge!
User | Count |
---|---|
123 | |
77 | |
71 | |
56 | |
48 |
User | Count |
---|---|
162 | |
84 | |
68 | |
66 | |
61 |