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 August 31st. Request your voucher.

Reply
alsm
Helper III
Helper III

Filter before applying sumx

I am performing sumx with multiplication across two tables as follows

ResultUSD2 =
VAR ResUSD = SUMX(ResultsLCYTbl, ResultsLCYTbl[ResultInLCY]*CALCULATE(VALUES(FxTbl[Rate]), TREATAS(SUMMARIZE(FxTbl,FxTbl[Currency],FxTbl[Date]),ResultsLCYTbl[Currency],ResultsLCYTbl[Date])))
Return     ResUSD
 
This works fine!
 
but before I send this ResultsLCYTbl into SUMX I want to filter ResultsLCYTbl  by values in another table (HeaderTbl)
 
i.e. something on lines
ResultUSD3 =
VAR select_date = SELECTEDVALUE(EomDates[Date])
VAR filt_headers = SUMMARIZE(FILTER(HeaderTbl, [ValidFrom] <= select_date && [ValidTo] >= select_date), HeaderTbl[HeaderKey])
VAR filt_reslcy = CALCULATE(VALUES(ResultsLCYTbl[ResultInLCY]), FILTER(ResultsLCYTbl, ResultsLCYTbl[HeaderKey] in filt_headers))
VAR ResUSD = SUMX(ResultsLCYTbl, ResultsLCYTbl[ResultInLCY]*CALCULATE(VALUES(FxTbl[Rate]), TREATAS(SUMMARIZE(FxTbl,FxTbl[Currency],FxTbl[Date]),ResultsLCYTbl[Currency],ResultsLCYTbl[Date])))
Return     ResUSD
 
i.e. filt_resöcy is the correct table on which i want to apply sumx
how would i do that?
 
 
Header Table
HeaderKeyValidFromValidTo
H11Jan202231Dec2022
H215Feb202231Oct2022
H310Mar202215Sep2022
H_FebOnly7Feb202225Feb2022
H_FebMar25Feb2022

14Apr2022

 
Monthly Results Table
DateNameResultInLCYCurrencyHeaderKey
Monday, 31 January 2022A25EURH1
Monday, 28 February 2022A53EURH1
Monday, 28 February 2022B92GBPH2
Monday, 28 February 2022D32GBPH_FebOnly
Monday, 28 February 2022E97USDH_FebMar
Thursday, 31 March 2022A74EURH1
Thursday, 31 March 2022B12GBPH2
Thursday, 31 March 2022C45AUDH3
Thursday, 31 March 2022D12GBPH_FebOnly
Thursday, 31 March 2022E87USDH_FebMar
Saturday, 30 April 2022A53EURH1
Saturday, 30 April 2022B74GBPH2
Saturday, 30 April 2022C98AUDH3

 

FX Table
DateCurrencyRate
Monday, 31 January 2022CAD1.2
Monday, 31 January 2022EUR1.1
Monday, 31 January 2022GBP1.07
Monday, 31 January 2022AUD1.4
Monday, 31 January 2022USD0.9
Monday, 28 February 2022CAD1.3
Monday, 28 February 2022EUR1.034
Monday, 28 February 2022GBP1.6
Monday, 28 February 2022AUD1.3
Monday, 28 February 2022USD1

 

 

so basically 'Monthly Results Table'[ResultsInLCY] *'FxTable['Rate'] works after joining these tables using TREATAS. However, I want to 'pre-filter' ResultsInLCY with Header Table falling in date range.

 

1 ACCEPTED SOLUTION
alsm
Helper III
Helper III

I figured it out!!

ResultUSD2 =
VAR select_date = MAX(EomDates[Date])
VAR filt_headers = SUMMARIZE(FILTER(HeaderTbl, [ValidFrom] <= select_date && [ValidTo] >= select_date), HeaderTbl[HeaderKey])
VAR filt_resultslcytbl = FILTER(ResultsLCYTbl, ResultsLCYTbl[HeaderKey] in filt_headers)
VAR ResUSD = SUMX(filt_resultslcytbl, [ResultInLCY]*CALCULATE(VALUES(FxTbl[Rate]), TREATAS(SUMMARIZE(FxTbl,FxTbl[Currency],FxTbl[Date]),ResultsLCYTbl[Currency],ResultsLCYTbl[Date])))
Return    
    ResUSD

 

for me what was a revelation was in line

VAR ResUSD = SUMX(filt_resultslcytbl, [ResultInLCY]*CALCULATE(VALUES(FxTbl[Rate]), TREATAS(SUMMARIZE(FxTbl,FxTbl[Currency],FxTbl[Date]),ResultsLCYTbl[Currency],ResultsLCYTbl[Date])))
 

using [ResultInLCY] directly in second part of SUMX, earlier i was trying to use it as

filt_resultslcytbl[ResultInLCY], which power bi complained

View solution in original post

1 REPLY 1
alsm
Helper III
Helper III

I figured it out!!

ResultUSD2 =
VAR select_date = MAX(EomDates[Date])
VAR filt_headers = SUMMARIZE(FILTER(HeaderTbl, [ValidFrom] <= select_date && [ValidTo] >= select_date), HeaderTbl[HeaderKey])
VAR filt_resultslcytbl = FILTER(ResultsLCYTbl, ResultsLCYTbl[HeaderKey] in filt_headers)
VAR ResUSD = SUMX(filt_resultslcytbl, [ResultInLCY]*CALCULATE(VALUES(FxTbl[Rate]), TREATAS(SUMMARIZE(FxTbl,FxTbl[Currency],FxTbl[Date]),ResultsLCYTbl[Currency],ResultsLCYTbl[Date])))
Return    
    ResUSD

 

for me what was a revelation was in line

VAR ResUSD = SUMX(filt_resultslcytbl, [ResultInLCY]*CALCULATE(VALUES(FxTbl[Rate]), TREATAS(SUMMARIZE(FxTbl,FxTbl[Currency],FxTbl[Date]),ResultsLCYTbl[Currency],ResultsLCYTbl[Date])))
 

using [ResultInLCY] directly in second part of SUMX, earlier i was trying to use it as

filt_resultslcytbl[ResultInLCY], which power bi complained

Helpful resources

Announcements
July PBI25 Carousel

Power BI Monthly Update - July 2025

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

Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 community update carousel

Fabric Community Update - June 2025

Find out what's new and trending in the Fabric community.