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

Date measures calculated on Date filter

Hi 

 

I am new to Power BI, and am now trying to migrate all my Excel reports into Power BI.

 

 

I have a measure to perform a count of values.

These values will then change based on teh date filter.

 

image.PNG

I now need to create a second measured value like above - but it needs to be a math date calculation that subtracts a week from the selected range (thus giving you the Previous Weeks volume) while displaying the present date filtered count too

Could someone please help me

Cheers

2 ACCEPTED SOLUTIONS
v-yulgu-msft
Employee
Employee

Hi @Acyrus1992,

 

Suppose there are two columns in source table Table[Date] and Table[Volume].

 

First, you should create a new table(in my test, it's named as Table2). Also, you need a calendar table (in my test, it's 'dim'). Remember to create a relationship between Table2 and dim. In Table2, create a calculated column to display the date a week ago.

Table2 =
SELECTCOLUMNS ( 'Table1', "date", 'Table1'[Date] )
7 days ago = DATEADD(dim[Date],-7,DAY) 

Then, create below measures:

Min = MIN('Date column'[7 days ago])
Max = MAX('Date column'[7 days ago])

Count volume for this week =
CALCULATE (
    COUNT ( 'Table1'[Used service] ),
    FILTER (
        'Table1',
        'Table1[Date] >= MIN ( 'Table2'[date] )
            && 'Table1'[Date] <= MAX ( 'Table2'[date] )
    )
)
Count volume for last week =
CALCULATE (
    COUNT ( 'Table1'[Used service] ),
    FILTER (
        'Table1',
        'Table1'[Date] >= [Min]
            && 'Table1'[Date] <= [Max]
    )
)

In slicer, you should add Table2[date] into field section. Dislay measures [Count volume for this week] and [Count volume for last week] in two card visual.

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Hi @Acyrus1992,

 

If you want to get the previous week value (74) when selecting current week number (18), you should also refer to the advice in my original reply.

 

First, you should create an extra table. And add a new column which display the last week number.

Table week =
SELECTCOLUMNS ( 'Platform Data', "weekNo", 'Platform Data'[Week Number] )

Last week No = 'Table week'[weekNo]-1 

Drag Table week[weekNo] into slicer.

 

Then, create measures like which is added into chart visual.

Tickets Raised =
CALCULATE (
    COUNTROWS ( 'Platform Data' ),
    FILTER ( 'Platform Data', 'Platform Data'[Resolution SLA] = "SLA Met" ),
    FILTER (
        'Platform Data',
        'Platform Data'[Data Type] = "Incident"
            || 'Platform Data'[Data Type] = "Service Request"
    ),
   FILTET(
   'Platform Data'[Week Number]=MAX('Table week'[Last week No]))
)

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

3 REPLIES 3
v-yulgu-msft
Employee
Employee

Hi @Acyrus1992,

 

Suppose there are two columns in source table Table[Date] and Table[Volume].

 

First, you should create a new table(in my test, it's named as Table2). Also, you need a calendar table (in my test, it's 'dim'). Remember to create a relationship between Table2 and dim. In Table2, create a calculated column to display the date a week ago.

Table2 =
SELECTCOLUMNS ( 'Table1', "date", 'Table1'[Date] )
7 days ago = DATEADD(dim[Date],-7,DAY) 

Then, create below measures:

Min = MIN('Date column'[7 days ago])
Max = MAX('Date column'[7 days ago])

Count volume for this week =
CALCULATE (
    COUNT ( 'Table1'[Used service] ),
    FILTER (
        'Table1',
        'Table1[Date] >= MIN ( 'Table2'[date] )
            && 'Table1'[Date] <= MAX ( 'Table2'[date] )
    )
)
Count volume for last week =
CALCULATE (
    COUNT ( 'Table1'[Used service] ),
    FILTER (
        'Table1',
        'Table1'[Date] >= [Min]
            && 'Table1'[Date] <= [Max]
    )
)

In slicer, you should add Table2[date] into field section. Dislay measures [Count volume for this week] and [Count volume for last week] in two card visual.

 

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Hi @v-yulgu-msft

 

Thank you for the response.

 

Before you replied, I added in some additional fields that Im hoping will help me achieve this easier.

I have the year Week number in the table too now.

 

So to get the count of rows for this week - I have written this:

 

Tickets Raised = CALCULATE(
COUNTROWS('Platform Data')
,FILTER('Platform Data'
,'Platform Data'[Resolution SLA] = "SLA Met"),FILTER('Platform Data','Platform Data'[Data Type] = "Incident" || 'Platform Data'[Data Type] = "Service Request"))

 

What this is doing, is only counting the rows in the dataset where the Resolution SLA is true, and where the Data Type is either value1 or value2

 

This gives me the correct figure for each week - when I select the week value.

IMg1.PNG

 

Now what I was hoping to acheive - is to write the same DAX in adding in a rule stating "Selected Week filter Value" - 1.

img2.PNG

 

Effectivly - Last Weeks value for Week 18 wuold then be 74

 

Does this make sence to you?

 

Im hoping it does haha

I am unable to find the right syntax and code to get it right yet

Any help would be greatly appreciated

Thank you

 

 

Hi @Acyrus1992,

 

If you want to get the previous week value (74) when selecting current week number (18), you should also refer to the advice in my original reply.

 

First, you should create an extra table. And add a new column which display the last week number.

Table week =
SELECTCOLUMNS ( 'Platform Data', "weekNo", 'Platform Data'[Week Number] )

Last week No = 'Table week'[weekNo]-1 

Drag Table week[weekNo] into slicer.

 

Then, create measures like which is added into chart visual.

Tickets Raised =
CALCULATE (
    COUNTROWS ( 'Platform Data' ),
    FILTER ( 'Platform Data', 'Platform Data'[Resolution SLA] = "SLA Met" ),
    FILTER (
        'Platform Data',
        'Platform Data'[Data Type] = "Incident"
            || 'Platform Data'[Data Type] = "Service Request"
    ),
   FILTET(
   'Platform Data'[Week Number]=MAX('Table week'[Last week No]))
)

Best regards,
Yuliana Gu

Community Support Team _ Yuliana Gu
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.

Top Solution Authors
Top Kudoed Authors