Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
4 years ago
Solved

Dynamic Index Column in granular matrix

Dear community,

 

I have a question and I hope you can help me out with this problem.

 

Assuming I have the following data set. The data set shows for a random supermarket prices for their offered drinks for different brands and also the prices from previous year.

 

 

IndexDrinkBrandActual Price in EURPrice Previous Year in EUROrder of Importance by Drink
1WaterBrand A211
2BeerBrand B336
3WineBrand C567
4SoftdrinkBrand B22,55
5Orange JuiceBrand B21,53
6WaterBrand C1,51,51
7BeerBrand A226
8WineBrand B447
9SoftdrinkBrand D2,525
10Orange JuiceBrand D333
11LemonadeBrand E224
12Apple JuiceBrand F2,532
13Apple JuiceBrand D322
14Orange JuiceBrand A3,533
15LemonadeBrand B2,524
16BeerBrand E436
17WineBrand F4,557
18LemonadeBrand C2,52,54
19WaterBrand B11,51
20WaterBrand E1,51,51

 

What I want to achieve is following scenario:

Each type of drink (water, beer…) has an order of importance and accordingly I want to sort it in a table matrix. E.g. for Water the Order of Importance is 1, for Beer is 6. Now I want to create a matrix table which display the drinks on first level and then on the more granular level for each brand, which is also not a problem. But my final goal would be to create a dynamic number (the red numbers in the screenshot) in front of the drink to display its current position like it is shown below.

 

At first, my approach was to combine the column “Drink” and column “Order of importance” which would work in a non-dynamic scenario. But e.g. if I now have a different data set for a supermarket which does not sell juices (Order of importance “2” and “3”) then I want the other drinks to move up in the list (Screenshot 3).

 

Any idea how to achieve this? 

 

 

 

 

 

 

  • Anonymous's avatar
    Anonymous
    4 years ago

    Hi Anonymous ,

    Please have a try.

    Measure_2 =
    VAR _countdrinks =
        CALCULATE ( DISTINCTCOUNT ( 'Table without'[Drink] ), ALL ( 'Table without' ) )
    VAR _maxcountdrinks =
        MAXX ( ALLSELECTED ( 'Table without' ), _countdrinks )
    VAR _yuanben =
        MAX ( 'Table without'[Order of Importance by Drink] )
    VAR _maxvalue =
        CALCULATE (
            MAX ( 'Table without'[Order of Importance by Drink] ),
            ALL ( 'Table without' )
        )
    VAR _rankx =
        RANKX (
            ALLSELECTED ( 'Table without' ),
            CALCULATE ( MAX ( 'Table without'[Order of Importance by Drink] ) ),
            ,
            DESC,
            DENSE
        )
    RETURN
        IF ( _maxcountdrinks <> _maxvalue, _rankx, _yuanben )
    

     

    If I have misunderstood your meaning, please provide your desired output with more details.

     

    Best Regards

    Community Support Team _ Polly

     

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

4 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi Anonymous ,

    Please refer to my pbix file to see if it helps you.

    Create a measure.

    Measure = IF(
    	ISERROR(
    		SEARCH("Juice",MAX('Table'[Drink]))
    	),
    	1,
    	BLANK()
    )

    Then filter the measure.

     

    f I have misunderstood your meaning, please provide your desired output with more details and you sample pbix file without privacy information.

     

    Best Regards

    Community Support Team _ Polly

     

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

     

  • Anonymous's avatar
    Anonymous
    Not applicable

    Anonymous thank you for your reply.

     

    I think I might misexplained my desired goal. 

    I dont want to exclude values which have  "Juice" in my dateset. Instead I am looking for a way to dynamically order my table/matrix in accordance to the column "Order of Importance by Drink".  To archieve this step I could "Sort by column" and then that would do the trick in my opinion. But additionally - and thats the hard part - I want to add dynamic numbers in front of each drink according to its current ranking ("Order of Importance by Drink"). Therefore my first approach was to combine column "Order of Importance by Drink" and column "Drink". But this would work only if all Drinks are included in this data set. So if have now a smaller dataset where the value "Orange Juice" does not exist at all, then all other drinks will stated still the same number in fron of their drink. I tried to show that in my "Not desired Output" stated below in the picture. For the drinks "Water" and "Apple Juice" is is correct ("1. Water" and "2. Apple Juice") but afterwards is the gap as "3. Orange Juice" is not part of the dataset and the numbers would be wrong ("4. Lemonade" is wrong but instead "3. Lemonade" would be correct). So what I want to archieve is that in case certain drinks are missing the number in front of the drink will be continiously in accordance to their order of the existing data. This is stated and marked in green on my desired output table.

     

     

    I also want to mention the dataset is only an example, but I am searching for a general approach which can be adapted to other data sets as well.

     

    Thanks in adance!

     

     

     

    • Anonymous's avatar
      Anonymous
      Not applicable

      Hi Anonymous ,

      Please have a try.

      Measure_2 =
      VAR _countdrinks =
          CALCULATE ( DISTINCTCOUNT ( 'Table without'[Drink] ), ALL ( 'Table without' ) )
      VAR _maxcountdrinks =
          MAXX ( ALLSELECTED ( 'Table without' ), _countdrinks )
      VAR _yuanben =
          MAX ( 'Table without'[Order of Importance by Drink] )
      VAR _maxvalue =
          CALCULATE (
              MAX ( 'Table without'[Order of Importance by Drink] ),
              ALL ( 'Table without' )
          )
      VAR _rankx =
          RANKX (
              ALLSELECTED ( 'Table without' ),
              CALCULATE ( MAX ( 'Table without'[Order of Importance by Drink] ) ),
              ,
              DESC,
              DENSE
          )
      RETURN
          IF ( _maxcountdrinks <> _maxvalue, _rankx, _yuanben )
      

       

      If I have misunderstood your meaning, please provide your desired output with more details.

       

      Best Regards

      Community Support Team _ Polly

       

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

      • Anonymous's avatar
        Anonymous
        Not applicable

        Hi Anonymous, thank you - that helped a lot. 

         

        I just changed afterwards the sort in measure_2 to "asc" and then created another measure where I concatenate the measure_2 and the needed column.

         

        Best