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.
I have the below tables, Emp and Date. Connected by Date.
In the front end I have user selecting the Year from Date Table. I am trying to create a measure, that calculates count of Pernr from my Emp table in the following condition. So if user selects current year (2018), the measure should be something like the below
calculate(count(Emp[Pernr]),Emp[Date]=First date of current year from Date table -1)
First date of current year from Date table -1 = 1/12018 - 1 = 12/31/2017
which will then give me something like the below:
calculate(count(Emp[Pernr]),Emp[Date]="12/31/2017")
Solved! Go to Solution.
To get around that error you have to do an explicit filter
formula = CALCULATE ( COUNT ( Emp[Pernr] ), FILTER(Emp, Emp[Date] = MAX ( Emp[Date] ) - 1 ) )
Hope this helps
David
Remove any existing filters on Emp by using ALL
CALCULATE ( COUNT ( Emp[Pernr] ),
Filter(ALL(Emp), Emp[Date] = MIN('Date'[Date])-1
))
Hi @eiprakash,
You can try to use below formula if it works for your scenario:
formula = CALCULATE ( COUNT ( Emp[Pernr] ), Emp[Date] = MAX ( Emp[Date] ) - 1 )
Regards,
Xiaoxin Sheng
I was not able to use the measure. I get the below error
A function 'MAX' has been used in a True/False expression that is used as a table filter expression. This is not allowed.
To get around that error you have to do an explicit filter
formula = CALCULATE ( COUNT ( Emp[Pernr] ), FILTER(Emp, Emp[Date] = MAX ( Emp[Date] ) - 1 ) )
Hope this helps
David
This is great ! It worked thanks.
As a followup from the same expression. I am trying to solve the following.
When user selects 2018, I would like to calculate a measure that does the following:
CALCULATE ( COUNT ( Emp[Pernr] ),
Filter(Emp, Emp[Date] = MIN('Date'[Date])-1
))
MIN('Date'[Date])-1 = 12/31/2017
Since I mention an explicit filter it filters Emp table to 2018 so this above measure returns a blank.
Greatly appreciate your help.
Remove any existing filters on Emp by using ALL
CALCULATE ( COUNT ( Emp[Pernr] ),
Filter(ALL(Emp), Emp[Date] = MIN('Date'[Date])-1
))
When I use ALL(Emp) function it is now not interacting with other filters. I would like to be able to do something like
- Filter Employees by other filters except date
Try setting the date value as a variable, then use ALLSELECTED
Measure = var Dt = calculate(MIN('Date'[Date])-1) return CALCULATE ( COUNT ( Emp[Pernr] ), Filter(ALLSELECTED(Emp), Emp[Date] = Dt) )
If that's still not working you may want to revisit why Date and Emp have an active relationship. Not all dates in the model necessarily need to be tied back to a calendar table.
Hope this helps
David
Thanks much ! Perfect worked well!
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
110 | |
94 | |
82 | |
66 | |
58 |
User | Count |
---|---|
151 | |
121 | |
104 | |
87 | |
67 |