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
Cado_one
Resolver III
Resolver III

Calculate a measure differently base on the time period selected in a slicer

Hi all,

 

I face an issue with a measure that looks simple but gives me difficulties.

 

The measure's objective is to return the count of trips on power plants and the difficulty is that the database has changed last year so we have to calculate the measure in a different way :

  • Before the 28/10/2020 : Count the distinct plant / day combinations
  • After the 27/10/2020 : Sum the value already calculated in a column of the table

Here is my measure :

nbDeplacements =
VAR ALTAIR_Access = IF(MAX(gmao_BI[DebutInterBI])<DATE(2020,10,28), COUNTROWS(GROUPBY(gmao_BI,gmao_BI[LocalisationBI],gmao_BI[DebutInterBI])), 0)
VAR MASTEM_Access = IF(MAX(gmao_BI[DebutInterBI])>DATE(2020,10,27), SUM(gmao_BI[NbreAccesSite]), 0)
RETURN ALTAIR_Access + MASTEM_Access
 
The problem is when I select a time period in the slicer which starts before and ends after the 28/10/2020, the measure is taking the Maximum date into account and not the entire period so only the second VAR applies.
 
Does anybody knows a function or a turnaround that could help me with that case please ?
 
Thanks in advance.
Regards,
Cado
1 ACCEPTED SOLUTION
amitchandak
Super User
Super User

@Cado_one , Based on what I got. Try a measure like

 

nbDeplacements =
VAR ALTAIR_Access = calculate(COUNTROWS(GROUPBY(gmao_BI,gmao_BI[LocalisationBI],gmao_BI[DebutInterBI])), filter(gmao_BI,gmao_BI[DebutInterBI]<DATE(2020,10,28)))+0
VAR MASTEM_Access = calculate(SUM(gmao_BI[NbreAccesSite]), filter(gmao_BI,gmao_BI[DebutInterBI]>DATE(2020,10,27)))+0
RETURN ALTAIR_Access + MASTEM_Access

View solution in original post

2 REPLIES 2
amitchandak
Super User
Super User

@Cado_one , Based on what I got. Try a measure like

 

nbDeplacements =
VAR ALTAIR_Access = calculate(COUNTROWS(GROUPBY(gmao_BI,gmao_BI[LocalisationBI],gmao_BI[DebutInterBI])), filter(gmao_BI,gmao_BI[DebutInterBI]<DATE(2020,10,28)))+0
VAR MASTEM_Access = calculate(SUM(gmao_BI[NbreAccesSite]), filter(gmao_BI,gmao_BI[DebutInterBI]>DATE(2020,10,27)))+0
RETURN ALTAIR_Access + MASTEM_Access

It's perfect thanks !

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.