Forum Discussion
IF condition across multiple tables returns blank/null values
- 2 years ago
Thanks all.
Only way i could solve it was to do a left join (merge) in power query using the caledar table as the base.
To achieve your desired output in Power BI using DAX, you can create a calculated column in Table2 (Transaction table) that incorporates the logic you mentioned. Since you want to display values in Table2 based on conditions involving both Table2 and Table1 (Calendar table), you can use functions like RELATED and FILTER. Here's a step-by-step guide on how to do this:
Open Power BI Desktop and go to the "Model" view.
Create a calculated column in Table2 (Transaction table) by following these steps:
- In the "Fields" pane, select "Table2."
- Click on the "Modeling" tab in the ribbon.
- Click on "New Column."
In the formula bar, enter the following DAX formula:
Symbol =
IF (
Table2[weekday_type] = "Weekend",
"symbol1",
IF (
Table2[weekday_type] = "weekday" && ISBLANK ( RELATED ( Calendar[ref date] ) ),
"symbol2",
BLANK ()
)
)
This formula creates a new column called "Symbol" in Table2. It checks the conditions you specified:
- If "weekday_type" in Table2 is "Weekend," it assigns "symbol1."
- If "weekday_type" is "weekday" in Table2 and the related "ref date" in Table1 (Calendar table) is blank, it assigns "symbol2."
If none of these conditions are met, it assigns a blank value.
- After entering the formula, press Enter to create the calculated column.
Now, your Table2 should have a new column called "Symbol" with the desired values based on your conditions.
- You can then use this "Symbol" column in your visuals to display the desired output.
Remember to adjust column and table names to match your actual data model. This DAX formula assumes that you have a one-to-many relationship between Table1 and Table2, as indicated by your table link type.
If this post helps, then please consider Accepting it as the solution to help the other members find it more quickly.
Hi 123abc
Thanks, but had no luck.
Tried a simple DAX as per below
Screenshot out out put
Data model