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.
Hi All,
I am new to DAX, can you please verify my dax .I am trying to create measure which should group by year, and make SFDB value to null and then add sfdb value to Null value
DAX:
I would really appreciate the help in advance.
Thanks
Solved! Go to Solution.
hi @suman1985
Hi @suman1985 ,
@talespin provides a good solution for you, while you can also try to follow my steps below:
Add two measures:
1&0 =
IF (
SELECTEDVALUE ( 'Table2'[NAME] ) = ""
|| SELECTEDVALUE ( 'Table2'[NAME] ) = "SFDB",
1,
0
)
Measure_Expected Result =
VAR _1 =
CALCULATE (
SUM ( 'Table2'[AMOUNT] ),
FILTER (
ALL ( 'Table2' ),
'Table2'[YEAR] = SELECTEDVALUE ( 'Table2'[YEAR] )
&& 'Table2'[1&0] = 1
)
)
VAR _2 =
IF (
SELECTEDVALUE ( 'Table2'[NAME] ) <> "",
SELECTEDVALUE ( 'Table2'[AMOUNT] ),
_1
)
RETURN
IF ( SELECTEDVALUE ( 'Table2'[NAME] ) = "SFDB", "", _2 )
Final output:
How to Get Your Question Answered Quickly - Microsoft Fabric Community
If it does not help, please provide more details with your desired out put and pbix file without privacy information.
Best Regards,
Ada Wang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Hi,
In my scenario the year and year-mon columns are coming from different table.I used the same measure which you have provided but it is not giving correct values
The table schema looks like
and the table structure and the result which we need for measure is highlighted in Yellow.
hi @h1629 ,
Please use this measure, it will SUM at either Year or Year-Month. Please note that the data I created doesn't have N/A for all months, so that is why you are not seeing N/A for certain months.
Hi @suman1985 ,
@talespin provides a good solution for you, while you can also try to follow my steps below:
Add two measures:
1&0 =
IF (
SELECTEDVALUE ( 'Table2'[NAME] ) = ""
|| SELECTEDVALUE ( 'Table2'[NAME] ) = "SFDB",
1,
0
)
Measure_Expected Result =
VAR _1 =
CALCULATE (
SUM ( 'Table2'[AMOUNT] ),
FILTER (
ALL ( 'Table2' ),
'Table2'[YEAR] = SELECTEDVALUE ( 'Table2'[YEAR] )
&& 'Table2'[1&0] = 1
)
)
VAR _2 =
IF (
SELECTEDVALUE ( 'Table2'[NAME] ) <> "",
SELECTEDVALUE ( 'Table2'[AMOUNT] ),
_1
)
RETURN
IF ( SELECTEDVALUE ( 'Table2'[NAME] ) = "SFDB", "", _2 )
Final output:
How to Get Your Question Answered Quickly - Microsoft Fabric Community
If it does not help, please provide more details with your desired out put and pbix file without privacy information.
Best Regards,
Ada Wang
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
Even this solution worked for me. Appreciate the help..
hi @suman1985
Thank you it worked for me. Great work.
I have a similar case where I am creating measure for Power BI Data model. Where I need to filter the fact tables and dim tables in the measure. This measure should work if end users wants to see year in the table or year month.
hi @h1629 ,
You can use this, replace with your table name and column names.
Thank you so much it worked..Great help .
User | Count |
---|---|
25 | |
12 | |
8 | |
6 | |
6 |
User | Count |
---|---|
26 | |
12 | |
11 | |
8 | |
6 |