Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello members.
I have a measure that works well but when I am trying to remove blanks from Filters then I get an error.
Specifically, I am checking if there are any salary changes month over month.
I am using 3 measures:
Salary CM = Calculate(SUM(HR[Salary]))
Salary PM = CALCULATE( SUM(Table1[Salary]),DATEADD('Time'[Month] , -1 , MONTH))
Salary Dif = IF(ISBLANK([Salary CM]),BLANK(),IF(ISBLANK([Salary PM]),BLANK(),IF([Salary CM]=[ Salary PM],BLANK(),[Salary CM]-[ Salary PM])))
I am using a Calendar table and the month column that I am using in the measures has a date format.
The measures works perfectly especially if I don't have a month slicer.
When i am adding a slicer and I am choosing for example 2 months I get some blank rows with the employees that was new hires.
I tried to remove those BLANKS by adding a filter that "Salary Dif" is not BLANK but I get an error:
Calculation error in measure Table1 [Salary PM]: Function 'DATEADD' expects a contiguous selection when the date column is not unique, has gaps or it contains time portion.
Date Salary EmployeeID
1/12/2021 800 99
1/12/2021 1000 100
1/12/2021 900 101
1/12/2021 1100 102
1/1/2022 1000 100
1/1/2022 900 101
1/1/2022 1100 102
1/1/2022 1300 103
1/2/2022 1400 100
1/2/2022 900 101
1/2/2022 1100 102
1/2/2022 1500 103
1/3/2022 1400 100
1/3/2022 1000 101
1/3/2022 1100 102
1/3/2022 1500 103
1/3/2022 1200 104
1/4/2022 1400 100
1/4/2022 1000 101
1/4/2022 1100 102
1/4/2022 1500 103
1/4/2022 1200 104
Is there any way to remove tha blank rows??
Thank you in advance, your help is always greatly appreciated
Solved! Go to Solution.
Hi, @Dimitris_Kats
Do you choose two non-consecutive months on the slicer? If you need to use dateadd function, you can only select consecutive months. If you don't want to select consecutive months, you may need to add year to slicer as well, then you can try like this:
Measure3 =
VAR a =
MIN ( 'Time'[Date] ) - 1
VAR b =
EOMONTH ( MAX ( 'Time'[Date] ), -1 )
VAR c =
DATE ( YEAR ( a ), MONTH ( a ), 1 )
VAR d =
DATE ( YEAR ( b ), MONTH ( b ), 1 )
RETURN
SUMX (
FILTER (
ALL ( 'Table1' ),
(
RELATED ( 'Time'[Date] ) >= c
&& RELATED ( 'Time'[Date] ) <= a
)
|| (
RELATED ( 'Time'[Date] ) >= d
&& RELATED ( 'Time'[Date] ) <= b
)
),
[Salary]
)
Did I answer your question? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.
Best Regards,
Community Support Team _ Janey
Hi, @Dimitris_Kats
Do you choose two non-consecutive months on the slicer? If you need to use dateadd function, you can only select consecutive months. If you don't want to select consecutive months, you may need to add year to slicer as well, then you can try like this:
Measure3 =
VAR a =
MIN ( 'Time'[Date] ) - 1
VAR b =
EOMONTH ( MAX ( 'Time'[Date] ), -1 )
VAR c =
DATE ( YEAR ( a ), MONTH ( a ), 1 )
VAR d =
DATE ( YEAR ( b ), MONTH ( b ), 1 )
RETURN
SUMX (
FILTER (
ALL ( 'Table1' ),
(
RELATED ( 'Time'[Date] ) >= c
&& RELATED ( 'Time'[Date] ) <= a
)
|| (
RELATED ( 'Time'[Date] ) >= d
&& RELATED ( 'Time'[Date] ) <= b
)
),
[Salary]
)
Did I answer your question? Please mark my reply as solution. Thank you very much.
If not, please feel free to ask me.
Best Regards,
Community Support Team _ Janey
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
12 | |
10 | |
6 |