I’m creating a measure, using the below virtual table. I know there are blank values in my ‘Work Orders’[Primary Code] column and I’d like to filter them out, I can’t seem to work out how to filter them out.
I wanted to use the logic that @MudassirAli used in his entry for Supplier Insight (If I remember correctly), so due to process errors the Primary Code field isn’t being filled out with every entry but we want to track those that are filled.
So I wanted to create Top Recurring values but it is returning blanks due to the high number of them. In the test data PBIX I sent on I’d want the blanks to be ignored so Primary Code A would be the top returning value.
Okay, I think I got both measures working according to spec:
You were extremely close on the first one – all you needed was to wrap your vTable variable in CALCULATETABLE and add a filter condition to get rid of the blanks:
The second one took a little more work – I used CONCATENATEX in the event that there are multiple codes with the same worst ISD value. I also used UNICHAR(10) as the delimiter to put each code on a different line in the card, but if you wanted to string them together you could substitute ". " as the delimiter parameter value.
Worst ISD by Primary Code Name =
VAR _vTable =
CALCULATETABLE(
ADDCOLUMNS(
SUMMARIZE( 'Work Orders', 'Work Orders'[Primary Code] ),
"@Primary Code", [ISD's]
),
FILTER( 'Work Orders', 'Work Orders'[Primary Code] <> BLANK() )
)
VAR NumWorst = [Worst#1 ISD's by Primary Code]
VAR Result =
CONCATENATEX(
FILTER( _vTable, [@Primary Code] = NumWorst ),
'Work Orders'[Primary Code],
UNICHAR( 10 ),
'Work Orders'[Primary Code], ASC
)
RETURN
Result
I hope this is helpful. Full solution file posted below.
@BrianJ Thanks for this, really appreciate the quick turnaround and you helping me understand that last final step. I hadn’t thought about the ties possibility so thank you for the foresight on that also.
Truly my pleasure – these types of virtual table DAX problems are some of my favorites to work out. I’m also working on a video on debugging techniques for virtual tables, and this will be a terrific example to illustrate a number of those points.
If you haven’t seen it already, Patrick LeBlanc has a terrific video out recently about how to work through these sorts of problems in DAX Studio or Tabular Editor. Highly recommended:
I’ve got to run to a meeting and don’t have time to test this theory, but I think what’s happening is related to how you’re calculating last seven days. I think what you DAX is doing is taking the last seven days of your date table, which would explain why it’s returning blanks. You can run a DAX query in DAX Studio or Tabular Editor to test that. Instead, try using a filter condition <= TODAY() && >= TODAY() -7.
Let me know how that goes, and if need be I can dig in in detail later.
The measure Worst#1 ISD’s by Primary Code seems to be doing it’s job dynamically when I use the date filter.
The measure Worst ISD by Primary Code Name is still returning a blank with what you suggested. I was hoping to make my measures dynamic to the date selected as I want to have measures that show
Last 7 days
Last 14 days
Last 28 days
Each having the Worst#1 ISD’s by Primary Code and the Worst ISD by Primary Code Name.
Your hardwired previous seven-day measure actually works fine because your day table dynamically ends at the last date in your fact table. However, to make this dynamic in the way you want, what I would do instead is add a Period Table slicer and customize it for the period you want (e.g., 7 days, 14 days, 24 days, etc.)
@JarrettM does this on almost all of this challenge entries and has an excellent video on how to implement this technique:
I hope this is helpful. Full solution file attached. Cool problem – enjoyed working with you on this.
I’m just about to turn the light out after reading some more of The Signal and the Noise…thought I’d check the forum and boom, there you go! Genuine big thanks on this and glad you enjoyed helping me on this. The more I ask questions on here the more my mind is being opened. Hopefully it’ll sink in haha!
Thanks for your help on this already Brian, I just have one last tweak to make and I can’t seem to resolve it.
I no longer need to create a Last 7 Days measure etc, just need the measures to work dynamically which they pretty much are with one slight blip.
I need to display the Top 3 Primary Codes by their Name and by their Number. So one card for the Primary Codes themselves and the Card below for the count/number. This works fine except when there is a tie. In the image I’ve posted the Worst 1 and Worst 2 cards both show the same values when I’d hoped the second card would drop down to the second values/numbers as per the graph below. So the #1Worst Cards would show A, G & 9, the #2Worst Cards would show B, BT, BZ, E & 4 and the #3Worst Card would show H and 2. Thanks in advance for any assistance given.