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
mzienowicz99
Helper I
Helper I

Writing a date filter in a measure

Hello!

 

I'm working on a report and want to get a variance in quantity of the same brand in two different months. My base table is looking pretty much like this (but it has a lot more columns):

mzienowicz99_0-1639149194242.png

 

And f.ex. I want a variance of quantity for brand Ferrari in 10.2021 in comparison to 10.2020?

How do you write a measure if you have a table looking like mine, I feel like I'm doing something wrong with writing a date in correct format.

 

My measure that I created to this moment looks like this:

YTY Variance = calculate([QTY](R2_INDUSTRY[BRAND]="JOHN DEERE",R2_INDUSTRY[ACTIVITY_MONTH]=2021-10)-([QTY](R2_INDUSTRY[BRAND]="JOHN DEERE",R2_INDUSTRY[ACTIVITY_MONTH]=2020-10)))

 

and [QTY] is just a basic measure giving the sum of [QUANTITY]

 

The result that I'm getting is:

mzienowicz99_1-1639149788559.png

 

How do you write a date in a measure, what could I possibly change? Thank you in advance 🙂

1 ACCEPTED SOLUTION
v-janeyg-msft
Community Support
Community Support

Hi, @mzienowicz99 

 

vjaneygmsft_0-1639558340570.png

According to your description, I think [activity_month] column is a date column or a string column.

If it is a date column, you can use [activity_month]=date(2021,10,1). If it is a string column, you can use [activity_month]="2021-10".

Like this:

YTY Variance =
CALCULATE (
    CALCULATE (
        [QTY],
        R2_INDUSTRY[BRAND] = "JOHN DEERE",
        R2_INDUSTRY[ACTIVITY_MONTH] = "2021 - 10" //R2_INDUSTRY[ACTIVITY_MONTH] = date(2021,10,1)
    )
        - (
            CALCULATE (
                [QTY],
                R2_INDUSTRY[BRAND] = "JOHN DEERE",
                R2_INDUSTRY[ACTIVITY_MONTH] = "2020 - 10" //R2_INDUSTRY[ACTIVITY_MONTH] = date(2020,10,1)
            )
        )
)

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

 

Best Regards,
Community Support Team _ Janey

View solution in original post

3 REPLIES 3
v-janeyg-msft
Community Support
Community Support

Hi, @mzienowicz99 

 

vjaneygmsft_0-1639558340570.png

According to your description, I think [activity_month] column is a date column or a string column.

If it is a date column, you can use [activity_month]=date(2021,10,1). If it is a string column, you can use [activity_month]="2021-10".

Like this:

YTY Variance =
CALCULATE (
    CALCULATE (
        [QTY],
        R2_INDUSTRY[BRAND] = "JOHN DEERE",
        R2_INDUSTRY[ACTIVITY_MONTH] = "2021 - 10" //R2_INDUSTRY[ACTIVITY_MONTH] = date(2021,10,1)
    )
        - (
            CALCULATE (
                [QTY],
                R2_INDUSTRY[BRAND] = "JOHN DEERE",
                R2_INDUSTRY[ACTIVITY_MONTH] = "2020 - 10" //R2_INDUSTRY[ACTIVITY_MONTH] = date(2020,10,1)
            )
        )
)

Did I answer your question ? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.

 

Best Regards,
Community Support Team _ Janey

@v-janeyg-msft 

THANK U, that solution works perfect 🙂

amitchandak
Super User
Super User

@mzienowicz99 , Seem like you have date to create a date from month year

 

Date = date(right([Month year],4) , left([Month year],2) ,1)

Now join this with date table and use time intelligence

 

 

examples

 

MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD('Date'[Date]))

last year MTD Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(dateadd('Date'[Date],-12,MONTH)))
Previous year Month Sales = CALCULATE(SUM(Sales[Sales Amount]),previousmonth(dateadd('Date'[Date],-11,MONTH)))
last year MTD (complete) Sales = CALCULATE(SUM(Sales[Sales Amount]),DATESMTD(ENDOFMONTH(dateadd('Date'[Date],-12,MONTH))))

 

 

Power BI — Month on Month with or Without Time Intelligence
https://medium.com/@amitchandak.1978/power-bi-mtd-questions-time-intelligence-3-5-64b0b4a4090e
https://www.youtube.com/watch?v=6LUBbvcxtKA

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.