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

The Power BI DataViz World Championships are on! With four chances to enter, you could win a spot in the LIVE Grand Finale in Las Vegas. Show off your skills.

Reply
Paulb123
New Member

DAX: return group from dimension table if there are existing record and return something if not.

So I have a fact table like sales data and product dimensional table. They are connected by product id. However, not all records from fact table have product id. I am wondering could I do some sort of DAX measure like following:

IF('fact_table'[product_id] = blank(),
    'product_table'[product_category],

     "something else" --- I would retrieve some text from a field in fact table, but I would like to know if this would work for fact table not containing key to dimension table

Thanks,

 

1 ACCEPTED SOLUTION
v-kongfanf-msft
Community Support
Community Support

Hi @Paulb123 ,

 

You can try formula like below to create calculated column:

ProductCategoryOrText = 
IF(
    ISBLANK('fact_table'[product_id]),
    'fact_table'[description],
    RELATED('product_table'[product_category])
)

vkongfanfmsft_0-1721814482433.png

Best Regards,
Adamk Kong

 

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

3 REPLIES 3
v-kongfanf-msft
Community Support
Community Support

Hi @Paulb123 ,

 

You can try formula like below to create calculated column:

ProductCategoryOrText = 
IF(
    ISBLANK('fact_table'[product_id]),
    'fact_table'[description],
    RELATED('product_table'[product_category])
)

vkongfanfmsft_0-1721814482433.png

Best Regards,
Adamk Kong

 

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

Ankit_Rai
Regular Visitor

Create a New Column

Enter the following DAX formula

 

 

ProductCategoryOrDefault = 
IF(
    ISBLANK('fact_table'[product_id]),
    "No Product ID",
    LOOKUPVALUE(
        'product_table'[product_category], 
        'product_table'[product_id], 
        'fact_table'[product_id], 
        "Category Not Found"
    )
)

 

 

Here's what the formula does:

  • ISBLANK('fact_table'[product_id]) checks if the product_id in the fact table is blank.
  • If the product_id is blank, it returns "No Product ID".
  • If the product_id is not blank, it uses LOOKUPVALUE to find the corresponding product_category from the product table.
  • If the product_id is not found in the product table, it returns "Category Not Found".

 

bhanu_gautam
Super User
Super User

@Paulb123 , You can use calculated column using related function 

 

NewColumn =
IF(
ISBLANK('fact_table'[product_id]),
RELATED('product_table'[product_category]),
"Some other text from fact table"
)




Did I answer your question? Mark my post as a solution! And Kudos are appreciated

Proud to be a Super User!




LinkedIn






Helpful resources

Announcements
Feb2025 Sticker Challenge

Join our Community Sticker Challenge 2025

If you love stickers, then you will definitely want to check out our Community Sticker Challenge!

Jan NL Carousel

Fabric Community Update - January 2025

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