Power BI is turning 10! Tune in for a special live episode on July 24 with behind-the-scenes stories, product evolution highlights, and a sneak peek at what’s in store for the future.
Save the dateEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.
Hello, I am a new PowerBI user. I tried to figure out how to convert one of tableau calculation to Power BI.
I want to calculate spend based on different formula if Program Name contain certain keywords. Program Name is a column with string value and Query1 is the table name.
Below is the measure I created, there is no syntax error but I got wrong result. I tried to change sumx to sum, but I was given an syntax error. Can anyone help to point out what I did wrong?
Spend V2 =
sumx(Query1,
SWITCH(
TRUE(),
CONTAINSSTRING(Query1[Program Name], "BT"),Query1[DCM_Impressions] * 24/1000,
CONTAINSSTRING(Query1[Program Name], "Endemic"),Query1[DCM_Impressions] * 50/1000,
CONTAINSSTRING(Query1[Program Name], "Comprehensive"),Query1[DCM_Impressions] * 90/1000,
CONTAINSSTRING(Query1[Program Name], "Retargeting") && Query1[report_date] >= Date(2022,07,01),Query1[DCM_Impressions] * 8/1000
)
Hi Jihwan_Kim, is there any workaround to avoid the error I encountered? Thanks
Date | Program Name | DCM Impressions |
1/1/2023 | Chevy LMA Blazer Awareness BT | 10000 |
1/2/2023 | Chevy LMA Blazer Awareness Endemic | 20000 |
1/5/2023 | Chevy LMA Blazer Conquest BT | 50000 |
1/6/2023 | Chevy LMA Blazer Conquest Endemic | 60000 |
1/10/2023 | Chevy LMA Blazer Retargeting | 100000 |
1/12/2023 | Chevy LMA Blazer Retention BT | 120000 |
1/13/2023 | Chevy LMA Blazer Awareness BT | 30000 |
1/14/2023 | Chevy LMA Blazer Awareness Endemic | 40000 |
1/17/2023 | Chevy LMA Blazer Conquest BT | 70000 |
1/18/2023 | Chevy LMA Blazer Conquest Endemic | 80000 |
1/22/2023 | Chevy LMA Blazer Retargeting | 120000 |
1/24/2023 | Chevy LMA Blazer Retention BT | 140000 |
I did pivot, my expect result should be below. Retail Spend Measure is calculated field based on the formula.
Program Name | DCM Impression | Retail Spend Measure |
Chevy LMA Blazer Awareness BT | 40000 | $960 |
Chevy LMA Blazer Awareness Endemic | 60000 | $3,000 |
Chevy LMA Blazer Conquest BT | 120000 | $2,880 |
Chevy LMA Blazer Conquest Endemic | 140000 | $7,000 |
Chevy LMA Blazer Retargeting | 220000 | $1,100 |
Chevy LMA Blazer Retention BT | 260000 | $6,240 |
Hi,
I am not sure how your datamodel looks like, but please try the below if it works.
Spend V2 measure =
SUMX (
Query1,
CALCULATE (
SWITCH (
TRUE (),
CONTAINSSTRING ( Query1[Program Name], "BT" ),
Query1[DCM_Impressions] * 24 / 1000,
CONTAINSSTRING ( Query1[Program Name], "Endemic" ),
Query1[DCM_Impressions] * 50 / 1000,
CONTAINSSTRING ( Query1[Program Name], "Comprehensive" ),
Query1[DCM_Impressions] * 90 / 1000,
CONTAINSSTRING ( Query1[Program Name], "Retargeting" )
&& Query1[report_date] >= DATE ( 2022, 07, 01 ),
Query1[DCM_Impressions] * 8 / 1000
)
)
)
Thanks Jihwan_Kim,
I tried to use the solution you provided, I got an error message.
"A single value for column 'Program Name' in table 'Query1' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifying an aggregation such as min, max, count, or sum to get a single result"
Check out the July 2025 Power BI update to learn about new features.
User | Count |
---|---|
22 | |
7 | |
6 | |
6 | |
6 |
User | Count |
---|---|
27 | |
10 | |
10 | |
9 | |
6 |