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
Anonymous
Not applicable

Group values from field with condition

Dear users,

 

I have a table with :

Vehicule - Line 

d4564564   -   M   

d7164564   -   L    

d4544575   -   P    

d4747422   -   M  

d4887564   -   O  

d4564564   -   M  

d4564564   -   L   

 

I want to display those values in a bar chart by group some lines values, like this :

Line - Count Vehicule

L = 2

M = 3

O = 1

P = 1

M-O = 4 

L-P = 3

 

=> How can I group like this ?

 

Thank you.

1 ACCEPTED SOLUTION
Anonymous
Not applicable

Hi @Anonymous ,

 

First create 2 tables as below:

 

Table 1 = 
ADDCOLUMNS('Table',"line2",'Table'[Line ])
Table 2 = CROSSJOIN(DISTINCT('Table'[Line ]),DISTINCT('Table 1'[line2]))

 

Then you will get all the combinations of the line;

Create a calculated column as below:

 

Line = IF('Table 2'[Line ]='Table 2'[line2],'Table 2'[Line ],CONCATENATE('Table 2'[Line ]&"-",'Table 2'[line2]))

 

And a measure as below:

 

Count Vehicule = IF(MAX('Table 2'[Line]) in FILTERS('Table'[Line ]),COUNTX(FILTER('Table','Table'[Line ]=MAX('Table 2'[Line])),'Table'[Line ]),COUNTX(FILTER('Table','Table'[Line ]=MAX('Table 2'[Line ])),'Table'[Line ])+COUNTX(FILTER('Table','Table'[Line ]=MAX('Table 2'[line2])),'Table'[Line ]))

 

Finally you will see:

Annotation 2020-06-29 131919.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!

View solution in original post

4 REPLIES 4
Anonymous
Not applicable

Hi @Anonymous ,

 

First create 2 tables as below:

 

Table 1 = 
ADDCOLUMNS('Table',"line2",'Table'[Line ])
Table 2 = CROSSJOIN(DISTINCT('Table'[Line ]),DISTINCT('Table 1'[line2]))

 

Then you will get all the combinations of the line;

Create a calculated column as below:

 

Line = IF('Table 2'[Line ]='Table 2'[line2],'Table 2'[Line ],CONCATENATE('Table 2'[Line ]&"-",'Table 2'[line2]))

 

And a measure as below:

 

Count Vehicule = IF(MAX('Table 2'[Line]) in FILTERS('Table'[Line ]),COUNTX(FILTER('Table','Table'[Line ]=MAX('Table 2'[Line])),'Table'[Line ]),COUNTX(FILTER('Table','Table'[Line ]=MAX('Table 2'[Line ])),'Table'[Line ])+COUNTX(FILTER('Table','Table'[Line ]=MAX('Table 2'[line2])),'Table'[Line ]))

 

Finally you will see:

Annotation 2020-06-29 131919.png

For the related .pbix file,pls click here.

 

Best Regards,
Kelly
Did I answer your question? Mark my post as a solution!
ryan_mayu
Super User
Super User

@Anonymous 

 

Maybe you can transform the table.

Table 3 = 
VAR TBL1= SUMMARIZE('Table (3)','Table (3)'[line],"count vehicule",count('Table (3)'[vehicule]))
VAR TBL2= SUMMARIZE('Table (3)',"line","M-O","count vehicule",COUNTX(FILTER('Table (3)','Table (3)'[line]="M" ||'Table (3)'[line]="O"), 'Table (3)'[vehicule]))
VAR TBL3=SUMMARIZE('Table (3)',"line","L-P","count vehicule",COUNTX(FILTER('Table (3)','Table (3)'[line]="L" ||'Table (3)'[line]="P"), 'Table (3)'[vehicule]))
RETURN UNION(TBL1,TBL2,TBL3)

1.PNG





Did I answer your question? Mark my post as a solution!

Proud to be a Super User!




Pragati11
Super User
Super User

Hi @Anonymous ,

 

You can achieve this as follows:

  1. Create a Clustered Bar chart in Power BI
  2. Drag "LINE" column to Axis
  3. Move COUNT of "VEHICLE" column in Values option.

Do you need grouping like "M-O" and "L-P" along with the existing values in "LINE" column?

 

 

Thanks,

Pragati

Best Regards,

Pragati Jain


MVP logo


LinkedIn | Twitter | Blog YouTube 

Did I answer your question? Mark my post as a solution! This will help others on the forum!

Appreciate your Kudos!!

Proud to be a Super User!!

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.