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

We've captured the moments from FabCon & SQLCon that everyone is talking about, and we are bringing them to the community, live and on-demand. Starts on April 14th. Register now

Reply
prat_daxer
New Member

Assigning a column value based on other column

I have data something like this:

Catagoryvaluefinal value
A11
A21
B22
B32
B42

Basically number 1,2,3,4 are priority and if any atagory has prio 1 also 2 assign both to 1.

2 ACCEPTED SOLUTIONS
pi_eye
Resolver IV
Resolver IV

It sounds like you are just trying to get the min of each group /category is that right?

You'll need an expression like

GroupMin = calculate(min('Table'[Value]), ALLEXCEPT('Table','Table'[Cat]))
Calculate will give you the min, the first parameter calculation, and the context is specified in the second paramter, AllExcept. In this case the context "all except" tells DAX to return all values in the table, ie, ignore all groupings per row, except the cat grouping.
 
This gives:
pi_eye_0-1665042673675.png

 

Pi

View solution in original post

The solution then is something like this:

Extended Logic =
var contains5= calculate(CONTAINS('Table','Table'[Value],5),ALLEXCEPT('Table','Table'[Category]))
var contains6=calculate(CONTAINS('Table','Table'[Value],6),ALLEXCEPT('Table','Table'[Category]))
return Switch (FIRSTNONBLANK( 'Table'[Category],0) ,
    "A",if(contains6,FIRSTNONBLANK('Table'[Value],0),5),
    "B",if(contains5,FIRSTNONBLANK('Table'[Value],0),6),
    "C",if(and(contains5,contains6),floor(5+rand()+0.25,1)))
 
vars contains5 and contains6 = these evaluate within the context of category, if the values 5 and 6 exist, respectively.

Switch Is similar to a case statement if you are familar with those - if you are not familiar think of it as an extended IF() statement where you can return multiple values depending on an input value.
 
Here we are passing the category to the switch statement, and depending on which category it is, returning a different value.
IF category is A, we look use contains 6 to determine what to return - either the value, or 5. Similar to B.
for C we are checking both contains5 and contains6 and if that's the case, using rand() to assign 5's and 6's
 
HTH 
Pi

View solution in original post

6 REPLIES 6
prat_daxer
New Member

 

Catagoryvaluefinal value
A55
A75
B76
B66
C55
C65
C55
C66

Condition 1: Cat A --> Assign prio 5 only if 6 is not there against A.

Condition 2: Cat B --> Assign prio 6 only if 5 is not present against B.

Condition 3: Cat C --> If prio 5 and 6 both present against C, assign random 75% 5's to cat C and in rest 25%, 6's.

There's as extended query to above problem. @pi_eye 

The solution then is something like this:

Extended Logic =
var contains5= calculate(CONTAINS('Table','Table'[Value],5),ALLEXCEPT('Table','Table'[Category]))
var contains6=calculate(CONTAINS('Table','Table'[Value],6),ALLEXCEPT('Table','Table'[Category]))
return Switch (FIRSTNONBLANK( 'Table'[Category],0) ,
    "A",if(contains6,FIRSTNONBLANK('Table'[Value],0),5),
    "B",if(contains5,FIRSTNONBLANK('Table'[Value],0),6),
    "C",if(and(contains5,contains6),floor(5+rand()+0.25,1)))
 
vars contains5 and contains6 = these evaluate within the context of category, if the values 5 and 6 exist, respectively.

Switch Is similar to a case statement if you are familar with those - if you are not familiar think of it as an extended IF() statement where you can return multiple values depending on an input value.
 
Here we are passing the category to the switch statement, and depending on which category it is, returning a different value.
IF category is A, we look use contains 6 to determine what to return - either the value, or 5. Similar to B.
for C we are checking both contains5 and contains6 and if that's the case, using rand() to assign 5's and 6's
 
HTH 
Pi
pi_eye
Resolver IV
Resolver IV

It sounds like you are just trying to get the min of each group /category is that right?

You'll need an expression like

GroupMin = calculate(min('Table'[Value]), ALLEXCEPT('Table','Table'[Cat]))
Calculate will give you the min, the first parameter calculation, and the context is specified in the second paramter, AllExcept. In this case the context "all except" tells DAX to return all values in the table, ie, ignore all groupings per row, except the cat grouping.
 
This gives:
pi_eye_0-1665042673675.png

 

Pi

prat_daxer
New Member

DAX would be good for me, I dont want to go on Mquery for this

pi_eye
Resolver IV
Resolver IV

Hi prat_daxer,

 

Are you trying to do this with DAX (front end UI) or M query (data shaping and modelling)

 

Pi

Helpful resources

Announcements
New to Fabric survey Carousel

New to Fabric Survey

If you have recently started exploring Fabric, we'd love to hear how it's going. Your feedback can help with product improvements.

Power BI DataViz World Championships carousel

Power BI DataViz World Championships - June 2026

A new Power BI DataViz World Championship is coming this June! Don't miss out on submitting your entry.

Join our Fabric User Panel

Join our Fabric User Panel

Share feedback directly with Fabric product managers, participate in targeted research studies and influence the Fabric roadmap.

March Power BI Update Carousel

Power BI Community Update - March 2026

Check out the March 2026 Power BI update to learn about new features.