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
anond
Regular Visitor

Show Column A value that matches particular condition in Column B

I have a database where column A is the name of the salesman and column B is the products they sold in January. Column C is the products they sold in Feb and so on, 

 

Salesman____Jan___Feb___Mar

A_____________100__101___98

B______________109__98____103

C_____________101___102___104

 

I want to create a new table that shows the names of the salesmen who sold the max in each of the months. So in the above case, it will look something like this:

 

Jan____B

Feb____C

Mar____C

 

Is there a way to do this? I tried creating a new measure that picks the MAX(Jan), MAX (Feb), etc, but that only picks the value. How do I pick the element from Column A corresponding to that?

 

Thanks all. 

1 ACCEPTED SOLUTION

@anond,

 

Yes. I mean the calculated table, not measure.

https://powerbi.microsoft.com/en-us/guided-learning/powerbi-learning-2-6-create-calculated-tables/

Community Support Team _ Sam Zha
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

11 REPLIES 11

Hi @anond

 

In case you need this on a matrix visual (not on an other table that you would load physically):

 

First, go to the Query Editor and unpivot your data.

Right click on Salesman column and "unpivot all the other columns".

Close & apply the steps of the query Editor.

 

Second, create the following measure:

Sales = Sum(YourTable[SalesColumn]

 

Third, compute who is the best performer:

Best Performer = Summarize ( TopN(1, YourTable, [Sales], DESC), YourTable[Salesmancolumn] )

 

Chose a matrix visual and put the month column as an axis, the "best performer" measure as a value.

Thank you so much for the help @Datatouille. I am a newbie (literally started working on Power BI today). So appreciate all your help here. I am yet to sit down and try to understand why we are doing each of these things. But I was not successful with the last step. 

 

This is how I have it for the Best Performer measure: https://imgur.com/a/VFOPK

 

Should we use TABLE in place of 'YourTable' in your post?
Also, I am not being prompted for Sheet1[SDR] for some reason (that's the Salesman field in your post). 

 

What am I doing wrong here? Thank you once again. 

Ok so you need a proper table ?

My solution was actually a measure.

 

Try this in a measure and adapt it to your example !

No, I don't need it as a column (or a measure) specifically. Just learning to do things at the moment. 

 

I did use 'Best Performer' as a measure. But it is throwing the error that you see in the screenshot. 

@anond would this not be a good case for unpivoting in power query?

 

http://chandoo.org/wp/2015/09/29/unpivot-data-with-power-query/





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




@vanessafvg Thanks for the link. But that only gives the tutorial for unpivoting which I was able to do on Power BI as well. I am trying to learn a way to find the highest seller for each month using Power BI.

@anond,

 

You may add a new table by DAX below.

Table =
FILTER (
    Sheet1,
    RANKX (
        CALCULATETABLE ( Sheet1, ALLEXCEPT ( Sheet1, Sheet1[Attribute] ) ),
        Sheet1[Value],
        ,
        DESC,
        DENSE
    )
        <= 1
)
Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@v-chuncz-msft

 

Thank you for your comment. I believe I would need to unpivot before creating this new table, right? I tried it and get an error that reads 'The expression refers to multiple columns. Multiple columns cannot be converted to a scalar value'. Any pointers here? 

 

 

@anond,

 

Yes. I mean the calculated table, not measure.

https://powerbi.microsoft.com/en-us/guided-learning/powerbi-learning-2-6-create-calculated-tables/

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

@anond oops sorry wasn't reading it properly!





If I took the time to answer your question and I came up with a solution, please mark my post as a solution and /or give kudos freely for the effort 🙂 Thank you!

Proud to be a Super User!




 

I also have a solution using Power Query

 

Salesman   Jan       Feb      March

A5010020
B103080
C1008010

This Table is called 'Data"


Power Query

Open the Query Editor and in the 'Data' Query 

Unpivot all the months, rename the appropriate columns and make sure your data type is OK.

This corresponds to the following M Code:

let
  Source = "YourSource"
  Unpiv = Table.UnpivotOtherColumns(Source, {"Salesman"}, "Month", "Amount"),
  ModifType = Table.TransformColumnTypes(Unpiv,{{"Amount", Int64.Type}})
in
  ModifType

 

Then, launch a new blank query with the following code:

let
 Source = Table.Group(Data, {"Month"}, {{"Best", each List.Max([Amount]), Int64.Type}}),
 DoubleMerge = Table.NestedJoin(Source,{"Month", "Best"},Data,{"Month", "Amount"},"Data",JoinKind.LeftOuter),
 Expand = Table.ExpandTableColumn(DoubleMerge, "Data", {"Salesman"}, {"Salesman"})
in
 Expand

 

In this solution, we are referencing the previous query 'Data' by grouping (by month) & getting the best salesman.

  

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.