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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
MaxPav
New Member

Get the repartition of a string variable

Hi,

 

I want want to get the repartition on a string variable.

The variable is "COUNTRY" :

 

COUNTRYNOTE
Italy90
Italy90
China90

 

and i want to get

 

COUNTRYNOTEWheight
Italy9066%
Italy9066%
China9033%

 

Maybe it is'nt yhe good wqay to do things. What i realy want is to exclude contry who have fews rows because they don't contribute but appears when i use median or average.

 

I am new in power BI so sorry if the answer is obvious.

 

Data source : data

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

Hi @MaxPav 

You can use DIVIDE dax to calculate the percentage of the number of rows in different countries to the total number of rows .

Measure = DIVIDE(COUNTA('Table'[COUNTRY]),CALCULATE(COUNTA('Table'[COUNTRY]),ALL('Table')))

Ailsa-msft_0-1622427919760.png

More info about the usage for DIVIDE dax can refer to the link :

https://docs.microsoft.com/en-us/power-bi/guidance/dax-divide-function-operator

 

Best Regards

Community Support Team _ Ailsa 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-yetao1-msft
Community Support
Community Support

Hi @MaxPav 

You can use DIVIDE dax to calculate the percentage of the number of rows in different countries to the total number of rows .

Measure = DIVIDE(COUNTA('Table'[COUNTRY]),CALCULATE(COUNTA('Table'[COUNTRY]),ALL('Table')))

Ailsa-msft_0-1622427919760.png

More info about the usage for DIVIDE dax can refer to the link :

https://docs.microsoft.com/en-us/power-bi/guidance/dax-divide-function-operator

 

Best Regards

Community Support Team _ Ailsa Tao

 

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

MaxPav
New Member

Hello myself,

I found this solution.

Step 1 : Power Query

#"Personnalisée ajoutée" = Table.AddColumn(#"Autres colonnes supprimées", "Personnalisé", each 1),
#"Personnalisée ajoutée1" = Table.AddColumn(#"Personnalisée ajoutée", "Personnalisé.1", each List.Sum(#"Personnalisée ajoutée"[Personnalisé])),
#"Colonnes renommées1" = Table.RenameColumns(#"Personnalisée ajoutée1",{{"Personnalisé.1", "Nb ligne"}}),
#"Autres colonnes supprimées1" = Table.SelectColumns(#"Colonnes renommées1",{"Num_Ligne", "country", "points", "price", "province", "region_1", "region_2", "title", "variety", "winery", "Nb ligne"})

 

Step 2 : Power BI, measures

Nb_Ligne_Country = COUNTA('winemag-data-130k-v2'[country])
TotalLigne = MAX('winemag-data-130k-v2'[Num_Ligne])
Poids = [Nb_Ligne_Country]/[TotalLigne]

I put this solution in case someone really needs it. However I think there must be a cleaner solution.

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.