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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
PhoenixBird66
Helper III
Helper III

DAX Column - use another value if field is blank

I am trying to create a DAX column or measure (not sure which would be best) and I'm not sure of the best way of doing this.

 

If the value in the Standard Service Code column is blank, I want the DAX mesaure to returns the first Standard Service Code from another row with the same document number.

 

So in the second and third rows in the picture below, the new measure/column would give you the standard service code of the first row (as all three rows have the same Document No_). Hope that makes sense? Any thoughts on the best way to do this?

 

Capture.JPG

1 ACCEPTED SOLUTION

Hi,

 

According to your description, i create a simple table to test:

111.PNG

Please try to create this calculated column:

Column = IF('Table'[Standard Service Code]=BLANK(),CALCULATE(MAX('Table'[Standard Service Code]),ALLEXCEPT('Table','Table'[Document No])),'Table'[Standard Service Code])

And the result shows:

112.PNG

Hope this helps.

 

Best Regards,

Giotto Zhi

View solution in original post

7 REPLIES 7
pb1051
Advocate II
Advocate II

Couldn't you also do a fill down in the query?

PhoenixBird66
Helper III
Helper III

This is how I acheived it in Excel (see last column Test), using this formula:

 

=IF(A2=A1,E1,C2)

 

I just don't know how to translate that to DAX 😞

 

Capture.JPG

Hi,

 

According to your description, i create a simple table to test:

111.PNG

Please try to create this calculated column:

Column = IF('Table'[Standard Service Code]=BLANK(),CALCULATE(MAX('Table'[Standard Service Code]),ALLEXCEPT('Table','Table'[Document No])),'Table'[Standard Service Code])

And the result shows:

112.PNG

Hope this helps.

 

Best Regards,

Giotto Zhi

amitchandak
Super User
Super User

Try

std service code = minx(filter(table,table[document_no]=earlier(table[document_no]) &&  not(isblank(table[standrad service code]))),table[standrad service code])
OR
std service code = minx(filter(table,table[document_no]=earlier(table[document_no]) &&  not(isblank(earlier(table[standrad service code])))),table[standrad service code])

 

Appreciate your Kudos. In case, this is the solution you are looking for, mark it as the Solution.
In case it does not help, please provide additional information and mark me with @

Thanks. My Recent Blogs -Decoding Direct Query - Time Intelligence, Winner Coloring on MAP, HR Analytics, Power BI Working with Non-Standard TimeAnd Comparing Data Across Date Ranges
Connect on Linkedin

Thanks for the suggestion, but sadly, neither of these work.

 

Here are my 2 attempts and a screen shot of the results.

 

Column = MINX(FILTER('US_Invoice Line', 'US_Invoice Line'[Document No_]=EARLIER('US_Invoice Line'[Document No_]) && NOT(ISBLANK(EARLIER('US_Invoice Line'[Standard Service Code])))), 'US_Invoice Line'[Standard Service Code])
 
And
 
Column 2 = MINX(FILTER('US_Invoice Line','US_Invoice Line'[Document No_]=EARLIER('US_Invoice Line'[Document No_]) && NOT(ISBLANK('US_Invoice Line'[Standard Service Code]))), 'US_Invoice Line'[Standard Service Code])
 
This is what they returned:
 
Capture.JPG

Can you share sample data. If possible please share a sample pbix file after removing sensitive information.Thanks.

My Recent Blog -

https://community.powerbi.com/t5/Community-Blog/HR-Analytics-Active-Employee-Hire-and-Termination-tr...

Gordonlilj
Solution Sage
Solution Sage

Hi,

 

Does the solution in the post below give you the result you're after?

https://community.powerbi.com/t5/Desktop/DAX-measure-Get-first-non-blank-record-ignoring-all-filters... 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

Find out what's new and trending in the Fabric Community.