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
elia22gr
Helper II
Helper II

dynamic column reference in an if statement

Hi all,

 

I have a following problem. In my company we have dynamic changing targets. For Example this month the target is on Products from Cat1 (this is under CATEGORY_1 column) and Br1 (this is under BRAND column) and PT1 (this is under PackType column) and the next month the target would be for products from SubCat2 (this is under SUBCATEGORY column) and PS2 (this is under PackSize column). 

CATEGORY_1, BRAND, PackType, SUBCATEGORY, PackSize are column in my Dim_Products Query.
I want to add a conditional column in my Dim_Products Table to use it as filter in my report, where it will bring 1 when the target conditions are met and 0 otherwise.

I have a Target_Mapping Table where I have the columns Names from my Dim_Products table and the value. 

NameColumn_Name_1Value_1Column_Name_2Value_2Column_Name_3Value_3
Target_SeptemberCATEGORY_1Cat_1BRANDBr1PackTypePT1

 How can I write the if statement in my Dim_Products table
Instead of hard-coding the [CATEGORY_1], [BRAND], [PackType] the columns reference to change it with the refence of the Target_Mapping Table under columns with header starting with "Column_Name_", picking each time the first row and put it as column reference in the if statement and as value again picking whatever is in the first row of columns with headers starting with "Value_".
if [Column_Name_1 first row] = Value_1 first row and [Column_Name_2 first row] = Value_2 first row and [Column_Name_3 first row] = Value_3 first row then 1 else 0

Thank you in advance,

Eleftheria

1 REPLY 1
lbendlin
Super User
Super User

Please provide sample data (with sensitive information removed) that covers your issue or question completely, in a usable format (not as a screenshot). Leave out anything not related to the issue.
If you are unsure how to do that please refer to https://community.fabric.microsoft.com/t5/Community-Blog/How-to-provide-sample-data-in-the-Power-BI-...
Please show the expected outcome based on the sample data you provided.

If you want to get answers faster please refer to https://community.fabric.microsoft.com/t5/Desktop/How-to-Get-Your-Question-Answered-Quickly/m-p/1447...

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.

Top Solution Authors
Top Kudoed Authors