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

Don't miss out! 2025 Microsoft Fabric Community Conference, March 31 - April 2, Las Vegas, Nevada. Use code MSCUST for a $150 discount. Prices go up February 11th. Register now.

Reply
KossithAz
Frequent Visitor

Set a value based on column text

Hi,

I have a dataset that contains financial years of 2021/22, 2022/23, 2023/24, 2024/25.

For 2021/22 & 2022/23, our target value is 118.
For 2023/24 & 2024/25, our target value is 110.

I'm trying to add a new column to the dataset that will do something along the lines of "if 2021/22" then "118", but I can't seem to get the formula correct.

Any suggestions would be appreciated 🙂

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

Hi @KossithAz ,

 

Thanks @techlog  for the quick reply. I have some other thoughts to add:

 

Based on the error message, it appears that you are creating a metric. If you need to create a measure, use the following formula.

vtangjiemsft_0-1716185468157.png

 

Measure = SWITCH(TRUE(),
MAX('Table'[Year])="2021/22",118,
MAX('Table'[Year])="2022/23",118,
MAX('Table'[Year])="2023/24",110,
MAX('Table'[Year])="2024/25",110,
BLANK())

If you need to create a calculated column, use the following formula.

vtangjiemsft_1-1716185547461.png

Column = SWITCH(TRUE(),
[Year]="2021/22",118,
[Year]="2022/23",118,
[Year]="2023/24",110,
[Year]="2024/25",110,
BLANK())

vtangjiemsft_2-1716185581112.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

4 REPLIES 4
v-tangjie-msft
Community Support
Community Support

Hi @KossithAz ,

 

Thanks @techlog  for the quick reply. I have some other thoughts to add:

 

Based on the error message, it appears that you are creating a metric. If you need to create a measure, use the following formula.

vtangjiemsft_0-1716185468157.png

 

Measure = SWITCH(TRUE(),
MAX('Table'[Year])="2021/22",118,
MAX('Table'[Year])="2022/23",118,
MAX('Table'[Year])="2023/24",110,
MAX('Table'[Year])="2024/25",110,
BLANK())

If you need to create a calculated column, use the following formula.

vtangjiemsft_1-1716185547461.png

Column = SWITCH(TRUE(),
[Year]="2021/22",118,
[Year]="2022/23",118,
[Year]="2023/24",110,
[Year]="2024/25",110,
BLANK())

vtangjiemsft_2-1716185581112.png

If the above one can't help you get the desired result, please provide some sample data in your tables (exclude sensitive data) with Text format and your expected result with backend logic and special examples. It is better if you can share a simplified pbix file. Thank you.

 

Best Regards,

Neeko Tang

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

Thank you very much, that has worked, and thank you to everyone else 🙂 

techlog
Frequent Visitor

Hi @KossithAz , Is this what you are looking for? Below is the formula.

techlog_1-1715959586707.png

 

 

 

Hi,

I've tried the above but have been hit with:

"A single value for column 'FIN_YEAR' in table 'table' cannot be determined. This can happen when a measure formula refers to a column that contains many values without specifiying an aggregation such as min, max, count or sum to get a single result".

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount! Prices go up Feb. 11th.

Jan25PBI_Carousel

Power BI Monthly Update - January 2025

Check out the January 2025 Power BI update to learn about new features in Reporting, Modeling, and Data Connectivity.

Jan NL Carousel

Fabric Community Update - January 2025

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