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.
Hi there,
As a part of a Power BI HR Dashboard, I want to showcase the yearly salary costs in a card visual as a rolling total per year. How I can transfer this to DAX code?
1. Result to achieve:
Example: Test data for year 2018:
Cost of Salary per certain year
32.000 €
Option to change specific year by slicer on Date Table
Columns to work with in fact table
Date Table & Fact table is connected via inactive relationships
‘Date’[Date] 1->* ‘Fact’[DateofHire]
‘Date’[Date] 1->* ‘Fact’[TermDate]
4. Data Set
https://1drv.ms/u/s!ApbrVj8RZyxnkWev_fGDrZQdMhls?e=K3hPy5
I would appreciate, if someone can help me out.
Cheers,
Martin
Solved! Go to Solution.
Hi @Mar82
This has to be a measure. It cannot be a calculated column. Please refer to attached amended sample file.
To handle blanks please use
Salary Amounts =
SUMX (
VALUES ( 'Date'[Year Month] ),
VAR MinDate = CALCULATE ( MIN ( 'Date'[Date] ) )
VAR MaxDate = CALCULATE ( MAX ( 'Date'[Date] ) )
RETURN
SUMX (
FILTER ( 'Kaggle', 'Kaggle'[DateofHire] <= MaxDate && COALESCE ( 'Kaggle'[TermDate], TODAY ( ) ) >= MinDate ),
'Kaggle'[SalaryMonthly]
)
)
Hi @Mar82
assuming both relationships are inactive, you may try
Salary Amounts =
VAR MinDate =
MIN ( 'Date'[Date] )
VAR MaxDate =
MAX ( 'Date'[Date] )
RETURN
SUMX (
FILTER ( 'Fact', 'Fact'[DateofHire] <= MaxDate && 'Fact'[TermDate] >= MinDate ),
'Fact'[SalaryMonthly]
)
Hi@tamerj1
Thanks a lot for your answer. I have added a FILTER argument to include also the Blanks for 'Fact'[TermDate].
Salary Amount :=
VAR MinDate = MIN('Date'[Date])
VAR MaxDate = MAX('Date'[Date])
RETURN
SUMX(
FILTER(
'Fact',
'Fact'[DateofHire] <= MaxDate && 'Fact'[TermDate] >= MinDate ||
'Fact'[DateofHire] <= MaxDate && 'Fact'[TermDate]=BLANK() // including TermDate Blanks //
),
'Fact'[SalaryMonthly]
)
Unfortunately I just have a single value for column [SalaryMonthly] per each employee even the person is employed multiple months.
As a result, the [Salary Amount] for e.g. a certain year is computed as if all the employees would have get just one single monthly salary paid out in that specific year.
How I can solve this?
Thanks for your support.
Cheers,
Martin
Hi @Mar82
This has to be a measure. It cannot be a calculated column. Please refer to attached amended sample file.
To handle blanks please use
Salary Amounts =
SUMX (
VALUES ( 'Date'[Year Month] ),
VAR MinDate = CALCULATE ( MIN ( 'Date'[Date] ) )
VAR MaxDate = CALCULATE ( MAX ( 'Date'[Date] ) )
RETURN
SUMX (
FILTER ( 'Kaggle', 'Kaggle'[DateofHire] <= MaxDate && COALESCE ( 'Kaggle'[TermDate], TODAY ( ) ) >= MinDate ),
'Kaggle'[SalaryMonthly]
)
)
@Mar82 Try this: (1) Better Running Total - Microsoft Power BI Community
Hi Greg,
thanks a lot for your reply and the link you provided. An entertaining rant on Calculate 😉
Unfortunately my starting point is a bit different from the example in your video.
First of all, I don't have the values ( in my case monthly salary) per each month.I just have it one time in the table per employee (EmpID).
Also I need to consider if a person ( based on their Hire or Term Date) is still employeed in a specific year and if so how many month.
May you have an idea to solve my issue?
Cheers,
Martin
User | Count |
---|---|
16 | |
15 | |
14 | |
12 | |
11 |
User | Count |
---|---|
19 | |
15 | |
14 | |
11 | |
9 |