Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Be 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

Reply
wooand
Helper II
Helper II

Using FIRSTNONBLANK unsuccessfully.

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?

 

1 ACCEPTED 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
        )
    )

View solution in original post

10 REPLIES 10
Greg_Deckler
Super User
Super User

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?



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
Power BI Cookbook Third Edition (Color)

DAX is easy, CALCULATE makes DAX hard...

Sure, here's a snip of the Excel data file as it stands:

 

Capture.PNG

 

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.

Clearly you are the expert!

@wooand

 

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 ACol BColC
ATRUEXYZ
ATRUEXYZ
AFALSEKLM
AFALSEABC
BTRUEKLM
BFALSEXYZ
CFALSEKLM
DTRUEABC

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.