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

Join us for an expert-led overview of the tools and concepts you'll need to become a Certified Power BI Data Analyst and pass exam PL-300. Register now.

Reply
EricaK
Regular Visitor

Value that occurs most often in a calculated column in another table

Hi there all,

 

Fairly new to DAX and i'm struggling right now to get a result in a calculated column.

 

What do I have:

Table Treatments

TreatmentIDTreated by Employee IDEpisodeIDCombineEpisodeEmployee
uniquenumberNumberNumberCalculatedColumn = helpcolumn
13011111-301
23011111-301
33041111-304
43042121-304
53042121-304

 

Table episodes

EpisodeIDMostTreatedEmployeeID
UniqueNumberCalculatedColumn
11301
21304

 

How can i calculate the MostTreatedEmployeeID?

 

I had it working in a reagular measure with the following code:

MostTreatedEmployeeID =
right(MAXX(TOPN(1,GROUPBY('Treatments','Treatments'[CombineEpisodeEmployee],"Count",COUNTX(CURRENTGROUP(), 'Treatments'[CombineEpisodeEmployee])), [Count], DESC), 'Treatments'[CombineEpisodeEmployee]),3)

 

Tho, when it is a measure I cannot use it in a matrix in the collumns or rows, which I want to. Or, can I?

 

I know that i have to put in the EpisodeID in the search somewhere, but i'm lost in the way how to... 

 

Thanks in advance!

 

 

7 REPLIES 7
v-echaithra
Community Support
Community Support

Hi @EricaK ,

We wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

 

Regards,
Chaithra.

v-echaithra
Community Support
Community Support

Hi @EricaK ,

Thank you @FBergamaschi , @SamsonTruong  for your inputs.

We wanted to kindly follow up to check if the solution provided for the issue worked? or Let us know if you need any further assistance?
If our response addressed, please mark it as Accept as solution and click Yes if you found it helpful.

 

Regards,
Chaithra.

FBergamaschi
Helper II
Helper II

Hi,

you cannot group a measure (put it in rows or columns in a mtarix) but you can group a column. So what you can do is group the EpisodeID from the Episode table and create a measure for the MostTreatedEmployeeID like follows:

 

Most Treated Employee ID =
VAR MaxNrTreatmentsByEmployee =
MAXX (
    VALUES ( Treatments[Treated by Employee ID] ),
    CALCULATE( COUNTROWS( Treatments ) )
)
VAR EployeeTreatments =
ADDCOLUMNS(
    VALUES ( Treatments[Treated by Employee ID] ),
    "@NrTreats", CALCULATE( COUNTROWS( Treatments ) )
)
VAR EmployeesMaxTreats =
FILTER (
    EployeeTreatments,
    [@NrTreats] = MaxNrTreatmentsByEmployee
)
RETURN
CONCATENATEX( EmployeesMaxTreats, [Treated by Employee ID], " / " )

 

Please note two things

1 - you cannot assume that the Most Treated Employee is a single one, and I considered the possibiliy they are mutiple

2 - To Improve your model, I suggest to create a table Employee and if you want I can change the above code considering this change

 

If this solves, please mark this post as a solution

 

Thanks!

Hi,

Thank you so much! This is a real good help for me!

The measure that you made is to put as a calculated column, right? Well, it works there 😉  It also works as a general measure, but I can't 

Your notes:

1 - Most treated is a single one: you are right! in 99% of the cases it is, and for the last percent I wanted to add (later) an extra part of the formula. If there are 2 (or more) then use another column -> MainContact.  I'm open for help in this part 😉 
2 - I do have a table Employee, but I don't see how you would change the code above? Use names in stead of ID numbers? Yes, I was planning on doing that. Wanted to get ID's first and a lookup isn't that hard.

 

Your response now gives all the ID's that have worked in this Episode. How can I get the one with the most treatments?

thanks in advance!

 

Hi Erika K

below my answers

 

Hi,

Thank you so much! This is a real good help for me!

The measure that you made is to put as a calculated column, right? 

 

FB no, I am using a column you have already, EpisodeID from the Episode table

 

  It also works as a general measure, but I can't 

 

FB what you can't is unclear to me

Your notes:

1 - Most treated is a single one: you are right! in 99% of the cases it is, and for the last percent I wanted to add (later) an extra part of the formula. If there are 2 (or more) then use another column -> MainContact.  I'm open for help in this part 

 

FB my code already considers this possibility

 
2 - I do have a table Employee, but I don't see how you would change the code above? Use names in stead of ID numbers? Yes, I was planning on doing that. Wanted to get ID's first and a lookup isn't that hard.

 

FB I meant connecting the Employee dimension table to the fact tables and subtitute in the DAX code the column Treatments[Treated by Employee ID] that comes from the fact table with the Employee ID from the Employee dimension table

 

Your response now gives all the ID's that have worked in this Episode. How can I get the one with the most treatments?

 

FB my code gives you already the ID of the employees with most treatments of that episode

thanks in advance!

 

FB you are welcome, if this is a solution please give kudos and mark as a solution, otherwise I am here at disposal

SamsonTruong
Impactful Individual
Impactful Individual

Hi @EricaK ,

One way to get around this is to replicate your logic as a calculated column. Here is your measure converted to a calculated column:

MostTreatedEmployeeID =
VAR CurrentEpisode = Episodes[EpisodeID]
VAR EpisodeTreatments =
    FILTER(
        Treatments,
        Treatments[EpisodeID] = CurrentEpisode
    )
VAR EmployeeFrequency =
    ADDCOLUMNS(
        SUMMARIZE(EpisodeTreatments, Treatments[Treated by Employee ID]),
        "Count", COUNTROWS(FILTER(EpisodeTreatments, Treatments[Treated by Employee ID] = EARLIER(Treatments[Treated by Employee ID])))
    )
VAR TopEmployee =
    TOPN(
        1,
        EmployeeFrequency,
        [Count], DESC,
        Treatments[Treated by Employee ID], ASC
    )
RETURN
    MAXX(TopEmployee, Treatments[Treated by Employee ID])

 

Once created, you can add this calculated column as a row or column in your matrix.

If this helped, please mark it as the solution so others can benefit too. And if you found it useful, kudos are always appreciated.

Thanks,

Samson

 

Connect with me on LinkedIn

Check out my Blog

Going to the European Microsoft Fabric Community Conference? Check out my Session



Unfortunately your code gives an #ERROR and I have trouble finding where it goes wrong. Thanks for helping tho! Really appreciated!

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.