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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
Manar
Helper II
Helper II

Difference between 2 columns in Matrix

Hi, I have the following Matrix and I would like to add another column with the difference between the rates of the 2 different periods columns (201803 & 201802), these 2 columns are from the same column (Reporting Period), when I connect to the data source I only bring the latest 2 periods (Direct Query).   Could you please help me out.testing.jpg

 

 

1 ACCEPTED SOLUTION

HI @Manar

 

Try this one

 

Measure =
CALCULATE (
    SUM ( ExchangeRatesFacts[ExchangeRate] ),
    FILTER (
        ALL ( ExchangeRatesFacts[ReportingPeriod] ),
        ExchangeRatesFacts[ReportingPeriod] = [CurrentReportingPeriod]
    )
)
    - CALCULATE (
        SUM ( ExchangeRatesFacts[ExchangeRate] ),
        FILTER (
            ALL ( ExchangeRatesFacts[ReportingPeriod] ),
            ExchangeRatesFacts[ReportingPeriod] = [LastReportingPeriod]
        )
    )

Regards
Zubair

Please try my custom visuals

View solution in original post

11 REPLIES 11
Zubair_Muhammad
Community Champion
Community Champion

HI @Manar

 

Try a MEASURE along following lines

 

Measure =
CALCULATE ( SUM ( TableName[Rates] ), TableName[ReportingPeriod] = 201803 )
    - CALCULATE ( SUM ( TableName[Rates] ), TableName[ReportingPeriod] = 201802 )

Regards
Zubair

Please try my custom visuals
Anonymous
Not applicable

What about if we have year more than 2 like 2015 , 2016 ,2017 ,2018 , 2019, 2020

@Zubair_Muhammad

 

I tried using your formula just added a measure instead of reporting period since they change every month

 

Measure = CALCULATE ( SUM ( ExchangeRatesFacts[ExchangeRate] ), ExchangeRatesFacts[ReportingPeriod] = CurrencyDim[CurrentReportingPeriod] )
    - CALCULATE ( SUM ( ExchangeRatesFacts[ExchangeRate] ), ExchangeRatesFacts[ReportingPeriod] = CurrencyDim[LastReportingPeriod])

 

and it gives me an error saying a function Calculate has been used in a true/false expression that is used as a table filter expression, This is not allowed.

 

 

@Manar

 

Hi,

 

Are these 2 MEASUREs?

 

CurrencyDim[CurrentReportingPeriod]

CurrencyDim[LastReportingPeriod]


Regards
Zubair

Please try my custom visuals

HI @Manar

 

Try this one

 

Measure =
VAR CurrentRP = [CurrentReportingPeriod]
VAR LastRP = [LastReportingPeriod]
RETURN
    CALCULATE (
        SUM ( ExchangeRatesFacts[ExchangeRate] ),
        ExchangeRatesFacts[ReportingPeriod] = CurrentRP
    )
        - CALCULATE (
            SUM ( ExchangeRatesFacts[ExchangeRate] ),
            ExchangeRatesFacts[ReportingPeriod] = LastRP
        )

Regards
Zubair

Please try my custom visuals

@Zubair_Muhammad It tells me function Filter is not supported in this context in DirectQuery Mode.   😞 

 

Thank you though!

HI @Manar

 

Try this one

 

Measure =
CALCULATE (
    SUM ( ExchangeRatesFacts[ExchangeRate] ),
    FILTER (
        ALL ( ExchangeRatesFacts[ReportingPeriod] ),
        ExchangeRatesFacts[ReportingPeriod] = [CurrentReportingPeriod]
    )
)
    - CALCULATE (
        SUM ( ExchangeRatesFacts[ExchangeRate] ),
        FILTER (
            ALL ( ExchangeRatesFacts[ReportingPeriod] ),
            ExchangeRatesFacts[ReportingPeriod] = [LastReportingPeriod]
        )
    )

Regards
Zubair

Please try my custom visuals

Hi @Zubair_Muhammad ,

 

Thanks for all of your insight in the forums. I have used your outline for my project but am unable to show any results. I have the same use case, where I need to get a variance between two months within a matrix. 

 

Here is my modified code:

 

Diff =
CALCULATE (
SUM ( Original[Tax] ),
FILTER (
ALL ( Original ),
Original[Period] = 3
)
)
- CALCULATE (
SUM ( Original[Tax] ),
FILTER (
ALL ( Original ),
Original[Period] = 2
)
)
 
I'm trying to get a difference in tax amount by month. Here is a picture of my scenario. Can you please help me? There is no error, only no data populating in a matrix. 
 pbi.PNG

@bjsrm8 

 

What if you remove the filter function?

 

Diff =
CALCULATE ( SUM ( Original[Tax] ), Original[Period] = 3 )
    - CALCULATE ( SUM ( Original[Tax] ), Original[Period] = 2 )

Regards
Zubair

Please try my custom visuals

@Zubair_Muhammad 

 

Still having the same issue with no data populating. I'm sure I'm missing something very easy but I can't figure it out. There are also no filters.

 

pbiv2.PNG

@Zubair_Muhammad Big Thank you!

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel

Fabric Monthly Update - May 2024

Check out the May 2024 Fabric update to learn about new features.

LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.