Join us for an expert-led overview of the tools and concepts you'll need to pass exam PL-300. The first session starts on June 11th. See you there!
Get registeredPower BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.
My data set has mixed granularity.
For salary calculations this is fine because I need to use all 3 lines.
For health, however, I only want to count the amount one time.
In Excel, I added a column to identify only the first line for each employee. Later, I used that column in the health calculations.
The formula I used was =IF(COUNTIF($B$3:B3,B3)=1,1,0)
Now I've migrated to a data model and need to add a similar calculated column.
What is the DAX translation for the Excel formula above?
Or is there a better way to accomplish this goal?
Thank you.
It's best to change the data model to something that follows Best Practices. If you do that, you'll have no problems with such calculcations. My suggestion is this. Create a dimension called Employee with columns Emp Number, Name, Health Premium. Then create a fact table Assignments with columns Emp Number, Assignment, FTE, Salary. Connect them with one-way filtering on Emp Number. All columns in fact tables should always be hidden and slicing should be only done via dimensions. Then create the required measures. [Total Health Premium] will be SUM( Employee[Health Premium] ). Easy. [Total Salary] will be SUM( Assignments[Salary] ). Easy again.
The secret to good end-user experience, fast and SIMPLE DAX lies in the model itself. If you have a bad model, you'll be always struggling with simple things and your DAX will be awful. Do you want that? No. I thought so 🙂
User | Count |
---|---|
16 | |
13 | |
12 | |
11 | |
11 |
User | Count |
---|---|
19 | |
15 | |
14 | |
11 | |
10 |