DAX - Items with no data

potap

New Member
Joined
Sep 5, 2014
Messages
43
Once again, I am stuck on something and ask for your help!

I got this measure :

Code:
=CALCULATE (
    SUM ( Sales[Sales] );
    Calender[isPast3Years] = TRUE ()
)

I have this pivot table that shows total sales by month :

[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]2013[/TD]
[TD]2014[/TD]
[TD]2015[/TD]
[/TR]
[TR]
[TD]01[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[/TR]
[TR]
[TD]02[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[/TR]
[TR]
[TD]03[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[/TR]
[TR]
[TD]04[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]850[/TD]
[/TR]
[TR]
[TD]05[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]06[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]07[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]08[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]09[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD][/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD][/TD]
[/TR]
</tbody>[/TABLE]

Right now, the 2012 colomn doesn't appear because of the isPast3Years in the Calculate but I do have transactions in the Sales table. I don't have any transaction in May 2015 and in the following months, obviously.

If I drag this measure instead :

Code:
=IF ( ISBLANK ( [TotalSales] ); 0; [TotalSales] )



[TABLE="class: grid, width: 500"]
<tbody>[TR]
[TD][/TD]
[TD]2012[/TD]
[TD]2013[/TD]
[TD]2014[/TD]
[TD]2015[/TD]
[/TR]
[TR]
[TD]01[/TD]
[TD]0[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[/TR]
[TR]
[TD]02[/TD]
[TD]0[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[/TR]
[TR]
[TD]03[/TD]
[TD]0[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[/TR]
[TR]
[TD]04[/TD]
[TD]0[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]850[/TD]
[/TR]
[TR]
[TD]05[/TD]
[TD]0[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]06[/TD]
[TD]0[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]07[/TD]
[TD]0[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]08[/TD]
[TD]0[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]09[/TD]
[TD]0[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]10[/TD]
[TD]0[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]11[/TD]
[TD]0[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]0[/TD]
[/TR]
[TR]
[TD]12[/TD]
[TD]0[/TD]
[TD]1000[/TD]
[TD]1000[/TD]
[TD]0[/TD]
[/TR]
</tbody>[/TABLE]

What I am looking for is a measure that gives 0 for every blank months in 2015 but not for 2012. I don't want to see any year that is not in the past 3. Tried Countrows() and other stuff but I wasn't able to figure something out :mad:

Thank you!!!
 

Excel Facts

How to change case of text in Excel?
Use =UPPER() for upper case, =LOWER() for lower case, and =PROPER() for proper case. PROPER won't capitalize second c in Mccartney
Forgot to specify that there might be months in past years that have no transaction. In this example, let's say that August 2012 as 0 transaction so 0 row.
 
Upvote 0
You could add an extra CALCULATE test, filtering all of the items in Sales. I don't know what the row differentiator is, so I used a field called ID and DAX measure of

=IF(CALCULATE( [TotalSales], ALL( Sales[Id] ) ) > 0, IF( ISBLANK( [TotalSales] ), 0, [TotalSales] ) )
 
Upvote 0
Thanks but this is the same as the first measure because there is is no sale in May 2015 so TotalSales is not > 0 and I will get a blank, not a 0.
 
Upvote 0
Got it to work!!!

Code:
=
IF (
    ISBLANK (
        CALCULATE (
            COUNTROWS ( Sales );
            ALL ( Calender[Month] );
            Calender[isPast3Years] = TRUE ()
        )
    );
    BLANK ();
    IF (
        ISBLANK ( _Measure[Sales (3 years)] );
        0;
        _Measure[Sales (3 years)]
    )
)
 
Upvote 0
I am thinking this would work?

=CALCULATE (
0 + SUM ( Sales[Sales] );
Calender[isPast3Years] = TRUE ()
)
 
Upvote 0
Yep, my bad :) Now I am annoyed by your question, because it feels like it should be easy...
 
Upvote 0
= IF (COUNTROWS(FILTER(Calendar, Calendar[IsPast3Years])) > 0, 0, BLANK()) +
SUM(Sales[Sales])

Look at the current context for rows in the past 3 years... if there are any... add a 0 to your measure.

Should work and perform well, but still feels a bit weird to me. <shrug>. Back to my coffee... :)
 
Upvote 0
I think you want to cater for not showing 2012 even when there are values in those months because it is not in past 3 years so I would use

Code:
[COLOR=#333333][FONT=Consolas]=[/FONT][/COLOR][COLOR=#0070FF][FONT=Consolas]IF[/FONT][/COLOR][COLOR=#D0D0D0][FONT=Consolas] ([/FONT][/COLOR]
[COLOR=#0070FF][FONT=Consolas]COUNTROWS[/FONT][/COLOR][COLOR=#D0D0D0][FONT=Consolas] ([/FONT][/COLOR][COLOR=#0070FF][FONT=Consolas]FILTER[/FONT][/COLOR][COLOR=#D0D0D0][FONT=Consolas] ([/FONT][/COLOR][COLOR=#333333][FONT=Consolas] Calendar, Calendar[IsPast3Years] [/FONT][/COLOR][COLOR=#D0D0D0][FONT=Consolas])[/FONT][/COLOR][COLOR=#D0D0D0][FONT=Consolas])[/FONT][/COLOR][COLOR=#333333][FONT=Consolas],[/FONT][/COLOR]
[COLOR=#0070FF][FONT=Consolas]IF[/FONT][/COLOR][COLOR=#D0D0D0][FONT=Consolas] ([/FONT][/COLOR][COLOR=#0070FF][FONT=Consolas]ISBLANK[/FONT][/COLOR][COLOR=#D0D0D0][FONT=Consolas] ([/FONT][/COLOR][COLOR=#333333][FONT=Consolas] [TotalSales] [/FONT][/COLOR][COLOR=#D0D0D0][FONT=Consolas])[/FONT][/COLOR][COLOR=#333333][FONT=Consolas], [/FONT][/COLOR][COLOR=#EE7F18][FONT=Consolas]0[/FONT][/COLOR][COLOR=#333333][FONT=Consolas], [TotalSales] [/FONT][/COLOR][COLOR=#D0D0D0][FONT=Consolas])[/FONT][/COLOR]
[COLOR=#D0D0D0][FONT=Consolas])[/FONT][/COLOR]
 
Last edited:
Upvote 0

Forum statistics

Threads
1,224,091
Messages
6,176,294
Members
452,719
Latest member
Boonchai Charoenek

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top