Forum Discussion

viralpatel21's avatar
viralpatel21
Helper II
5 years ago
Solved

multiple values from different table and show previous month value

Hello everyone,   I hope you can help me. I have 2 tables: FX Rates table and Month FX table. I want to multiply each months monthly value with FX rates. But when it comes to the last month i.e: N...
  • v-alq-msft's avatar
    5 years ago

    Hi, viralpatel21 

     

    Based on your description, I created data to reproduce your scenario. The pbix file is attached in the end.

    FX Rate:

     

    Month fx:

     

    There is a relationship between two tables based on 'Months' column. You may create two measures as below.

    Measure SUM fx RATE x EUR = 
    SUMX(
        SUMMARIZE(
            'Month fx',
            'Month fx'[Months],
            "Result",
            var m = MAX('Month fx'[MonthValue])
            var lastmonth = 
            CALCULATE(
                MAX('Month fx'[MonthValue]),
                FILTER(
                    ALL('Month fx'),
                    [MonthValue]<m
                )
            )
            var eurfx = 
            CALCULATE(
                SUM('FX Rate'[EUR_Avg]),
                FILTER(
                    ALL('FX Rate'),
                    [MonthValue]=lastmonth
                )
            )
            var eurmfx = 
            CALCULATE(
                SUM('Month fx'[EUR_Avg]),
                FILTER(
                    ALL('Month fx'),
                    [MonthValue]=lastmonth
                )
            )
            return
            IF(
                ISBLANK(SUM('FX Rate'[EUR_Avg]))||ISBLANK(SUM('Month fx'[EUR_Avg])),
                eurfx*eurmfx,
                SUM('FX Rate'[EUR_Avg])*SUM('Month fx'[EUR_Avg])
            )
        ),
        [Result]
    )
    Measure SUM fx RATE x GBP = 
    SUMX(
        SUMMARIZE(
            'Month fx',
            'Month fx'[Months],
            "Result",
            var m = MAX('Month fx'[MonthValue])
            var lastmonth = 
            CALCULATE(
                MAX('Month fx'[MonthValue]),
                FILTER(
                    ALL('Month fx'),
                    [MonthValue]<m
                )
            )
            var gbpfx = 
            CALCULATE(
                SUM('FX Rate'[EUR_Avg]),
                FILTER(
                    ALL('FX Rate'),
                    [MonthValue]=lastmonth
                )
            )
            var gbpmfx = 
            CALCULATE(
                SUM('Month fx'[EUR_Avg]),
                FILTER(
                    ALL('Month fx'),
                    [MonthValue]=lastmonth
                )
            )
            return
            IF(
                ISBLANK(SUM('FX Rate'[GBP_Avg]))||ISBLANK(SUM('Month fx'[GBP_Avg])),
                gbpfx*gbpmfx,
                SUM('FX Rate'[GBP_Avg])*SUM('Month fx'[GBP_Avg])
            )
        ),
        [Result]
    )

     

    Result:

     

    Best Regards

    Allan

     

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