Forum Discussion

alsm's avatar
alsm
Helper III
3 years ago
Solved

Lookup value on filtered table

hello,

I have multiple tables that need to be filtered on selected date and data from different tables multiplied. Any hints?

Header Table
HeaderKeyDetailsKeyValidFromValidTo
H1D11Jan202231Dec2022
H2D215Feb202231Oct2022
H3D310Mar2022

15Sep2022

 

Details Table
DetailsKeyNameCurrencyVolume
D1AEUR500
D2BGBP700
D3CAUD250

 

Limit Table
HeaderKeyLimitVolumeValidFromValidTo
H15001Jan202215Feb2022
H145015Feb202231Mar2022
H14001Apr202231Dec2022
H270015Feb20221Mar2022
H25501Mar202231Oct2022
H325010Mar20221May2022
H32501May202215Sep2022

 

FX Table
DateCurrencyRate
31-JanCAD1.2
31-JanEUR1.1
31-JanGBP1.07
31-JanAUD1.4
31-JanUSD0.9
28-FebCAD1.3
28-FebEUR1.034
28-FebGBP1.6
28-FebAUD1.3
28-FebUSD1

 

If SelectedValue for date = 28Feb, I want to show on screen

CurrencyLimitVolumeLimitVolume (USD)
EUR450465.3
GBP7001120

 

What I have to do (if I were to write a program)

1. I have filtered HeaderTable first find what is valid on 28Feb

2. I have found all the distinct currency from Details for the header

3. I have filtered LimitTable to find LimitVolume on 28Feb

4. I have found FX rate on 28-Feb for the currencies

5. Grouped by currency shown Limit in Local currency & the convered USD value

 

No combination of lookup on filtered table to do LimitVolume*Rate seems to be working

Any other way that Lookup?

  • I solved it by adding one column after another using ADDCOLUMNS. Happy to hear from someone a more DAX like solution (this was closer to series of Lookups)

    VolumeLimit (USD) = 
    VAR FilteredHeaderTbl = FILTER(ALL(HeaderTbl), HeaderTbl[ValidFrom] < [SelectEoM] && HeaderTbl[ValidTo] >=[SelectEoM])
    VAR FilteredNames = CALCULATETABLE(VALUES(HeaderTbl[DetailsKey]),FilteredHeaderTbl)
    VAR FilteredHeaderIds = CALCULATETABLE(VALUES(HeaderTbl[HeaderKey]),FilteredHeaderTbl)
    VAR FilteredLimitTbl = CALCULATETABLE(VolumeLimitTbl,FILTER(VolumeLimitTbl, VolumeLimitTbl[ValidFrom] < [SelectEoM] && VolumeLimitTbl[ValidTo] >= [SelectEoM]), FilteredHeaderIds)
    VAR FilteredDetailsTbl =  CALCULATETABLE(DetailsTbl,FilteredNames)
    VAR WithHeaderId = ADDCOLUMNS(FilteredDetailsTbl,"hkey",CALCULATE(MAX(HeaderTbl[HeaderKey]),FILTER(FilteredHeaderTbl, [DetailsKey] == EARLIER(DetailsTbl[DetailsKey]))))
    VAR WithLimit = ADDCOLUMNS(WithHeaderId,"vol_limit", CALCULATE(MAX(VolumeLimitTbl[LimitVolume]),FILTER(FilteredLimitTbl,[HeaderKey] == EARLIER([hkey]))))
    VAR WithFX = ADDCOLUMNS(WithLimit,"rate", LOOKUPVALUE(FxTbl[Rate],FxTbl[Date],[SelectEoM],FxTbl[Currency],[Currency]))
    VAR TotalLimit = CALCULATE(SUMX(WithFX,[vol_limit]*[rate]))
    RETURN
        TotalLimit

3 Replies

  • alsm's avatar
    alsm
    Helper III

    I solved it by adding one column after another using ADDCOLUMNS. Happy to hear from someone a more DAX like solution (this was closer to series of Lookups)

    VolumeLimit (USD) = 
    VAR FilteredHeaderTbl = FILTER(ALL(HeaderTbl), HeaderTbl[ValidFrom] < [SelectEoM] && HeaderTbl[ValidTo] >=[SelectEoM])
    VAR FilteredNames = CALCULATETABLE(VALUES(HeaderTbl[DetailsKey]),FilteredHeaderTbl)
    VAR FilteredHeaderIds = CALCULATETABLE(VALUES(HeaderTbl[HeaderKey]),FilteredHeaderTbl)
    VAR FilteredLimitTbl = CALCULATETABLE(VolumeLimitTbl,FILTER(VolumeLimitTbl, VolumeLimitTbl[ValidFrom] < [SelectEoM] && VolumeLimitTbl[ValidTo] >= [SelectEoM]), FilteredHeaderIds)
    VAR FilteredDetailsTbl =  CALCULATETABLE(DetailsTbl,FilteredNames)
    VAR WithHeaderId = ADDCOLUMNS(FilteredDetailsTbl,"hkey",CALCULATE(MAX(HeaderTbl[HeaderKey]),FILTER(FilteredHeaderTbl, [DetailsKey] == EARLIER(DetailsTbl[DetailsKey]))))
    VAR WithLimit = ADDCOLUMNS(WithHeaderId,"vol_limit", CALCULATE(MAX(VolumeLimitTbl[LimitVolume]),FILTER(FilteredLimitTbl,[HeaderKey] == EARLIER([hkey]))))
    VAR WithFX = ADDCOLUMNS(WithLimit,"rate", LOOKUPVALUE(FxTbl[Rate],FxTbl[Date],[SelectEoM],FxTbl[Currency],[Currency]))
    VAR TotalLimit = CALCULATE(SUMX(WithFX,[vol_limit]*[rate]))
    RETURN
        TotalLimit
  • v-yinliw-msft's avatar
    v-yinliw-msft
    Community Support

    Hi alsm ,

     

    I think you can add a column or a measure in the FX table to calculate the LimitVolume * Rate.

     

    Best Regards,

    Community Support Team _Yinliw

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • alsm's avatar
      alsm
      Helper III

      v-yinliw-msft  Thank you for your reply...

      I need to filter first before i do this multiply

       

      so for 28Feb, the filters are

      Header Table
      HeaderKeyDetailsKeyValidFromValidTo
      H1D11Jan202231Dec2022
      H2D215Feb2022

      31Oct2022

       

      Details Table
      DetailsKeyNameCurrencyVolume
      D1AEUR500
      D2BGBP700

       

      Limit Table   
      HeaderKeyLimitVolumeValidFromValidTo
      H145015Feb202231Mar2022
      H270015Feb20221Mar2022

       

      FX Table  
      DateCurrencyRate
      28-FebEUR1.034
      28-FebGBP1.6

       

      and this filtered table need to be multiplied ...

      problem is i cannot get my head around on how to apply complex filter (validfrom and validto) and use the result to multiply