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
modwonka
Helper I
Helper I

Calculated column

Hi there,

 

I know this has to be really easy but I can't find the solution. Any idea?

 

i have two tables.

 

1- id clients

2- id clients, units sale per row

 

i would like to add a calculated column in the first table.  If the ID has more or equal than 2 units in a row from table 2 (without sum), this ID is "teacher", if the id has less of 2 units, the id would be "alumn". And third condition, if the id has different rows with less than 2 units and others row with 2 or more units, the id would be "mixed".

 

thanks!

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

Hi @modwonka ,

 

You can check the attachment for the detailed information.

 

Create a index in power query and then create following calculated columns

 

id1 = CALCULATE(MAX('Table (2)'[id clients]),FILTER('Table (2)',[Index]=EARLIER('Table (2)'[Index])-1))
flag = IF([id clients]=[id1],1,0)
flag2 = SUMX(FILTER(ALL('Table (2)'),[id clients]=EARLIER('Table (2)'[id clients])),[flag])
Type = IF([flag2]+1=COUNTROWS(FILTER('Table (2)',[id clients]=EARLIER('Table (2)'[id clients]))),"teacher",IF([flag2]=0,"album","mixed"))

 

4.png

 

Then you can use LOOKUPVALUE to match type in the first table.

Type = LOOKUPVALUE('Table (2)'[Type],'Table (2)'[id clients],'Table'[id clients])

14.png

 

 

Best Regards,

Stephen Tao

 

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

2 REPLIES 2
v-stephen-msft
Community Support
Community Support

Hi @modwonka ,

 

You can check the attachment for the detailed information.

 

Create a index in power query and then create following calculated columns

 

id1 = CALCULATE(MAX('Table (2)'[id clients]),FILTER('Table (2)',[Index]=EARLIER('Table (2)'[Index])-1))
flag = IF([id clients]=[id1],1,0)
flag2 = SUMX(FILTER(ALL('Table (2)'),[id clients]=EARLIER('Table (2)'[id clients])),[flag])
Type = IF([flag2]+1=COUNTROWS(FILTER('Table (2)',[id clients]=EARLIER('Table (2)'[id clients]))),"teacher",IF([flag2]=0,"album","mixed"))

 

4.png

 

Then you can use LOOKUPVALUE to match type in the first table.

Type = LOOKUPVALUE('Table (2)'[Type],'Table (2)'[id clients],'Table'[id clients])

14.png

 

 

Best Regards,

Stephen Tao

 

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

AlB
Super User
Super User

Hi @modwonka 

I don't understand the requirement. Do you want to show some data, a sample of both tables and explain what you need based on that data, with the expected result?

Secondly, do you want this in DAX or Power query?

 

SU18_powerbi_badge

Please accept the solution when done and consider giving a thumbs up if posts are helpful. 

Contact me privately for support with any larger-scale BI needs, tutoring, etc.

 

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