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

Power BI is turning 10! Let’s celebrate together with dataviz contests, interactive sessions, and giveaways. Register now.

Reply
reynold522
Helper II
Helper II

in a table creat a measure base on two column values

Hi, 

 

I  would like to creat a  measure base on condition of two table column.

 

if column: BAT_TYPE is A, and column: CAPACITY_AH is 210, then value should be 168

if column: BAT_TYPE is A, and column: CAPACITY_AH is 100, then value should be 80

if column: BAT_TYPE is E, and column: CAPACITY_AH is 240, then value should be 120

if column: BAT_TYPE is S, and column: CAPACITY_AH is 225, then value should be 45

 

the dax code writen is as following:

 

Capacitythreshold = SWITCH(
TRUE(),
Table[BAT_TYPE]="A"&&Table[CAPACITY_AH]=210, 168,
Table[BAT_TYPE]="A"&&Table[CAPACITY_AH]=100, 80,
Table[BAT_TYPE]="E"&&Table[CAPACITY_AH]=240, 120,
Table[BAT_TYPE]="S"&&Table[CAPACITY_AH]=225, 45,
BLANK()
)

I got following error meesage:

A single value for column 'BAT_TYPE' in table 'Table' 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.

 

Thanks in advance!

1 ACCEPTED SOLUTION
FreemanZ
Super User
Super User

hi @reynold522 

A measure depends heavely on the filter context. Without knowing the filter context, there is always issue.

Why don't create a calculated column with the same code and plot a visual with that column?

Actually the way you use SWITCH is the typical way of using SWTCH for calculated columns. 

View solution in original post

6 REPLIES 6
FreemanZ
Super User
Super User

hi @reynold522 

A measure depends heavely on the filter context. Without knowing the filter context, there is always issue.

Why don't create a calculated column with the same code and plot a visual with that column?

Actually the way you use SWITCH is the typical way of using SWTCH for calculated columns. 

thanks, actually I made it before your answer.

Anyway, thanks! I accept your solution as answer. 

hi @reynold522 

It is always the best to raise a question, discuss with someone, then realize the solution by oneself. 

Samarth_18
Community Champion
Community Champion

Hi @reynold522 ,

 

You could use below code if you are using these columns on the visual:-

Capacitythreshold =
SWITCH (
    TRUE (),
    MAX ( Table[BAT_TYPE] ) = "A"
        && MAX ( Table[CAPACITY_AH] ) = 210, 168,
    MAX ( Table[BAT_TYPE] ) = "A"
        && MAX ( Table[CAPACITY_AH] ) = 100, 80,
    MAX ( Table[BAT_TYPE] ) = "E"
        && MAX ( Table[CAPACITY_AH] ) = 240, 120,
    MAX ( Table[BAT_TYPE] ) = "S"
        && MAX ( Table[CAPACITY_AH] ) = 225, 45,
    BLANK ()
)

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

sorry it is grammatically correct however, not able to generate the result I need.

 

Still thanks

Can you share the sample data(raw not screenshot) with expected output pls?

Best Regards,
Samarth

If this post helps, please consider accepting it as the solution to help the other members find it more quickly.
Appreciate your Kudos!!
Connect on Linkedin

Helpful resources

Announcements
Join our Fabric User Panel

Join our Fabric User Panel

This is your chance to engage directly with the engineering team behind Fabric and Power BI. Share your experiences and shape the future.

June 2025 Power BI Update Carousel

Power BI Monthly Update - June 2025

Check out the June 2025 Power BI update to learn about new features.

June 2025 community update carousel

Fabric Community Update - June 2025

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