cancel
Showing results for 
Search instead for 
Did you mean: 
Reply
PhoenixBird66 Regular Visitor
Regular Visitor

firstnonblank or MAX - measure to return the first value in a column based on another column

I'm having real problems writing a measure to return the first value in a column based on whether another column is blank or not.

 

I have 2 tables - Price History and Sales. They are joined by a one to many relationship based on a key (a concatentation of service code & unit price.).

 

I want to write a measure that will return the first (as in earliest) value where the Quantity Sold is not blank for each part (or StdSvcKey). So in the case below the number I want for this part is £621.86.

 

Capture.PNG

 

 

 

 

 

 

 

I've tried 2 different methods so far but they dont do what i want.

 

I tried:

 

= FIRSTNONBLANK(PRICEHISTORY[Unit Price],0)
 
But this retruned the value £0.01
 
I also tried adding a caluclated column (DaysSincePriceChanged) to give me the number of days since the start date of the price change, so that I could then use MAX:
 
  CALCULATE(
   MAX( PRICEHISTORY [Unit Price]),
   KEEPFILTERS(
FILTER(
       PRICEHISTORY ,
   PRICEHISTORY [DaysSincePriceChanged] = CALCULATE(MAX(PRICEHISTORY [DaysSincePriceChanged]), ALLEXCEPT(PRICEHISTORY , PRICEHISTORY [StdSvcKey]))
     )
   ),
   ALLEXCEPT(PRICEHISTORY ,  PRICEHISTORY [StdSvcKey])
)
 
but this returns a value of £604.80, so thats not right either.
 
Any ideas guys?
2 ACCEPTED SOLUTIONS

Accepted Solutions
v-jiascu-msft Super Contributor
Super Contributor

Re: firstnonblank or MAX - measure to return the first value in a column based on another column

Hi @PhoenixBird66 ,

 

Please try this formula below, which is more intuitive. 

 

Measure 2 =
MINX (
    TOPN (
        1,
        FILTER ( 'Table1', 'Table1'[Quantity Sold] <> BLANK () ),
        Table1[Start Date], ASC
    ),
    [Unit Price]
)

 

 

 

Best Regards,

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

v-jiascu-msft Super Contributor
Super Contributor

Re: firstnonblank or MAX - measure to return the first value in a column based on another column

Hi @PhoenixBird66 ,

 

Could you please mark the proper answers as solutions?

 

 

Best Regards,

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

5 REPLIES 5
Highlighted
GauravSingh Regular Visitor
Regular Visitor

Re: firstnonblank or MAX - measure to return the first value in a column based on another column

hi,

 

this might be happening because you have some page filter on.

 

please see the link below, this will give you a clear understanding

 

Link

v-jiascu-msft Super Contributor
Super Contributor

Re: firstnonblank or MAX - measure to return the first value in a column based on another column

Hi @PhoenixBird66 ,

 

Try this simpler one. The key point here is the row context that we need to convert.

Measure =
FIRSTNONBLANK (
    Table1[Unit Price],
    CALCULATE ( SUM ( Table1[Quantity Sold] ) )
)

firstnonblank-or-MAX-measure-to-return-the-first-value-in-a-column-based-on-another-column

Best Regards,

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.
PhoenixBird66 Regular Visitor
Regular Visitor

Re: firstnonblank or MAX - measure to return the first value in a column based on another column

Thanks for your response.

 

I've tried this but it seems to be picking up the first (as in smallest) value rather than the first (as in oldest value). So in this example it returns the value £25.12, but I want it to return the value £26.00.

 

I need it to return the OLDEST unit price (based on the Start Date column) where the Quantity Sold is not blank or zero.

 

Capture.PNG

v-jiascu-msft Super Contributor
Super Contributor

Re: firstnonblank or MAX - measure to return the first value in a column based on another column

Hi @PhoenixBird66 ,

 

Please try this formula below, which is more intuitive. 

 

Measure 2 =
MINX (
    TOPN (
        1,
        FILTER ( 'Table1', 'Table1'[Quantity Sold] <> BLANK () ),
        Table1[Start Date], ASC
    ),
    [Unit Price]
)

 

 

 

Best Regards,

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

v-jiascu-msft Super Contributor
Super Contributor

Re: firstnonblank or MAX - measure to return the first value in a column based on another column

Hi @PhoenixBird66 ,

 

Could you please mark the proper answers as solutions?

 

 

Best Regards,

Community Support Team _ Dale
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

Helpful resources

Announcements
Can You Solve These Challenge

Challenge: Can You Solve These?

Find out how to participate in the first Power BI 'Can You Solve These?' challenge.

New Badges

Incoming: New and Improved Badges

Exciting news: We've given our badges an overhaul and added brand news ones.

Ask Amir Anything

Exclusive LIVE Community Event No. 2 – Ask Amir Anything

Next in our Triple A series: Ask Amir Netz questions about the latest updates, features and future.

Analytics in Azure virtual event

Analytics in Azure virtual event

Experience a limitless analytics service built to ingest, prep, manage, and serve data for immediate use in Power BI.

Users Online
Currently online: 179 members 2,068 guests
Please welcome our newest community members: