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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
antoniosantos
Frequent Visitor

How to display months, comparing current against previous period in a bar visual with a date slicer?

Hello,

The measure calculates sliced period's values, but I'd need to compare it with previous period. I've come this far, but since the slicer says `this month`, then it won't show the past months, given this measure.

 

TotalVpago_pcveicul_Comparison = 
VAR SelectedFilter =
    FILTER(
        pclanc,
        pclanc[CODCONTA] IN 
        CALCULATETABLE(
            VALUES(pcconta[CODCONTA]),
            pcconta[GRUPOCONTA] IN {501, 510},
            NOT(ISBLANK(pcconta[CODCONTAMASTER])),
            pcconta[CODCONTAMASTER] IN 
            CALCULATETABLE(
                VALUES(pcveicul[CODVEICULO]),
                pcveicul[CODLOCALIZACAO] = 1
            )
        )
    )

VAR SelectedPeriodVPAGO = 
    CALCULATE(
        SUM(pclanc[VPAGO]),
        SelectedFilter
    )
    
VAR PreviousPeriodVPAGO = 
    IF(
        HASONEVALUE(pclanc[Date]),   // Check if there's a single date value in the drill-through filter
        CALCULATE(
            SUM(pclanc[VPAGO]),
            SAMEPERIODLASTYEAR(pclanc[Date]),
            SelectedFilter
        ),
        BLANK()  // Return blank when there's no single date value (i.e., drill-through filter removed)
    )
    
RETURN
    SelectedPeriodVPAGO + PreviousPeriodVPAGO

 

 

This is what it shows, but I'd like it to show previous months and their comparisons from last year's months.

antoniosantos_0-1690668423888.png

Appreciate any help!

 

1 REPLY 1
TomMartens
Super User
Super User

Hey @antoniosantos,

 

i recommend reading this article: https://www.daxpatterns.com/time-patterns/

The article contains almost everything one needs to know about date/time related calculations. It also explains why these type of calculations require a dedicated data table (the first step to a star schema).

Hopefully, this gets you started.

 

Regards,

Tom



Did I answer your question? Mark my post as a solution, this will help others!

Proud to be a Super User!
I accept Kudos 😉
Hamburg, Germany

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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