March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Early bird discount ends December 31.
Register NowBe one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now
I have data in three columns in table 'Results'. The columns are:
A: Deal Reference
B: Deal Time
C: Deal Rate
All cells contain numbers, no text.
I need to identify the very first Deal Rate in the list, ordered by time. I have had minor success using FIRSTNONBLANK, but it isn't returning the first rate when ordered by time. It's returning something from the middle of the list with no obvious reason to me why that's the case!
Can anyone help please?
Solved! Go to Solution.
HI @wooand
Try this formula
Formula = VAR FirstNonBlankTradeStartTime = CALCULATE ( FIRSTNONBLANK ( ALL ( Results[Trade Start Time] ), TRUE () ) ) RETURN CALCULATE ( FIRSTNONBLANK ( Results[Dealt Rate], 1 ), FILTER ( ALL ( Results ), Results[Trade Start Time] = FirstNonBlankTradeStartTime ) )
Can you post the DAX for your formula? And could you post some sample data? Are you looking for the firstnonblank for each Deal Reference?
Sure, here's a snip of the Excel data file as it stands:
It carries on in the same vein for several thousand lines.
By using = CALCULATE(FIRSTNONBLANK(Results[Dealt Rate], TRUE()) I get a value, but I want the first one in terms of the Trade Start Time. I'm concerned that there may be a millisecond issue here to boot, but anyway, any help most welcome.
HI @wooand
And that value returned would be the minimum of all the DEALT RATES??? Is it?
No, in this example I would want 1.1726 at the first Trade Time (it's ordered by Trade Time), but for some reason I'm getting some other rate from elsewhere in the data series.
HI @wooand
Try this formula
Formula = VAR FirstNonBlankTradeStartTime = CALCULATE ( FIRSTNONBLANK ( ALL ( Results[Trade Start Time] ), TRUE () ) ) RETURN CALCULATE ( FIRSTNONBLANK ( Results[Dealt Rate], 1 ), FILTER ( ALL ( Results ), Results[Trade Start Time] = FirstNonBlankTradeStartTime ) )
Nicely done Zubair. That was way beyond me, so thanks.
I wrote this Article few days ago
http://www.excelnaccess.com/using-firstnonblank-lastnonblank-in-dax/
Clearly you are the expert!
Actually FirstNonBlank /LastNonBlank return the first/last nonblank value respectively in the column…..after sorting the column in its native Ascending Order….
Hi Zubair,
Is there a way to stop the native sorting of column in Ascending order? The dataset that I have already has it sorted in a particular order and I just want to pick the first record. I am basically doing a lookup to get the first value in sample[ColC] for matching Col A in 'data' table.
mappedColC= CALCULATE (
FIRSTNONBLANK (sample[ColC],1 ),
FILTER ( ALL ( sample),sample[Col A]=data[ColA] )
)
The table sample below is already sorted in this order, sort by Col A Asc, then Col B desc. Then, pick the first value of ColC for each Col A. In the below sample the desired output would be for 'A'= XYZ, 'B'=KLM, 'C'=KLM, 'D'=ABC. But as per your explanation, I now understand why I am getting 'A'=ABC. I tried to add the additional condition
FILTER ( ALL ( sample),sample[Col A]=data[ColA] && sample[Col B]=TRUE )
then it picks XYZ for A, but misses to pick KLM for 'C' and that retuns (blank). Please help.
Col A | Col B | ColC |
A | TRUE | XYZ |
A | TRUE | XYZ |
A | FALSE | KLM |
A | FALSE | ABC |
B | TRUE | KLM |
B | FALSE | XYZ |
C | FALSE | KLM |
D | TRUE | ABC |
March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!
Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.
Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.
User | Count |
---|---|
123 | |
86 | |
76 | |
57 | |
52 |
User | Count |
---|---|
201 | |
137 | |
108 | |
73 | |
68 |