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
shanu_123
Frequent Visitor

How to make measure dynamic based on DATE selection via Date Slicer

"Today Sales= CALCULATE(COUNT(pbi_stock_sold[is_sold_from_stock]),FILTER(pbi_stock_sold,pbi_stock_sold[SoldDate]=TODAY()))" 

"Yesterday Sales  = CALCULATE(COUNT(pbi_stock_sold[is_sold_from_stock]),FILTER(pbi_stock_sold, pbi_stock_sold[SoldDate].[Date]=TODAY()-1))"

"This week Sales= CALCULATE(COUNT(pbi_stock_sold[is_sold_from_stock]),FILTER(pbi_stock_sold,YEAR(pbi_stock_sold[SoldDate])=YEAR(TODAY())&&WEEKNUM(pbi_stock_sold[SoldDate])=WEEKNUM(TODAY())))"

"This month Sales = CALCULATE(COUNT(pbi_stock_sold[is_sold_from_stock]),FILTER(pbi_stock_sold,YEAR(pbi_stock_sold[SoldDate])=YEAR(TODAY()) && MONTH(pbi_stock_sold[SoldDate])=MONTH(TODAY())))"

"This year Sales = CALCULATE(COUNT(pbi_stock_sold[is_sold_from_stock]),FILTER(pbi_stock_sold,YEAR(pbi_stock_sold[SoldDate])=YEAR(TODAY())))"

 

How can make above measure dynamic based on date selection in date slicer? They are static only show for recent date. Please guide....

1 ACCEPTED SOLUTION
v-yulgu-msft
Employee
Employee

Hi @shanu_123,

 

First, you need a calendar table which lists continual unique date values. Don't need to create a relationship between this calendar table and 'pbi_stock_sold'.

CalendarTable=CALENDAR(DATE(2017,1,1),DATE(2018,12,31))

 

Add [date] column from 'CalendarTable' to slicer.

 

Modify original measures to replace TODAY() with MAX('CalendarTable'[date]), for example:

Yesterday Sales  = CALCULATE(COUNT(pbi_stock_sold[is_sold_from_stock]),FILTER(pbi_stock_sold, pbi_stock_sold[SoldDate].[Date]=MAX('CalendarTable'[date])-1))

 

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

2 REPLIES 2
v-yulgu-msft
Employee
Employee

Hi @shanu_123,

 

First, you need a calendar table which lists continual unique date values. Don't need to create a relationship between this calendar table and 'pbi_stock_sold'.

CalendarTable=CALENDAR(DATE(2017,1,1),DATE(2018,12,31))

 

Add [date] column from 'CalendarTable' to slicer.

 

Modify original measures to replace TODAY() with MAX('CalendarTable'[date]), for example:

Yesterday Sales  = CALCULATE(COUNT(pbi_stock_sold[is_sold_from_stock]),FILTER(pbi_stock_sold, pbi_stock_sold[SoldDate].[Date]=MAX('CalendarTable'[date])-1))

 

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,
I'm using this method to filter the values in my measures and it works perfectly, but when the measure is referenced in a table the table does not display the change made to the measure by the filter.
The measure used for the date:

Dia Variable = MAX('Tabla Calendario'[Date])

The calculated measure using the method to change the date:

M_ECO_6m= 

VAR DIA = [Dia Variable]

VAR MOTI = 0+CALCULATE(

    COUNT('SB'[ANTIGUEDAD]),

    'SB'[ANTIGUEDAD]IN { "+6M" },

    NOT('SB'[GC] IN {"GC"}),

    'SB'[date_op] = DIA,

    'SB'[Description] IN {"MO_ECO"} 
)
RETURN MOTI


The table im creating:

M_SB = {("M_Eco",[M_ECO_6m],[%_eco_6m],[M_ECO_X],[%_eco_x],[MO_ECO_G],[%_eco_g])}

when i put the measure in a KPI card it works fine but in the custom table it doesnt update with the filter.

Thanks in advance.

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.