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

Be one of the first to start using Fabric Databases. View on-demand sessions with database experts and the Microsoft product team to learn just how easy it is to get started. Watch now

Reply
WMansueto
Frequent Visitor

Fill Columns based on rank measure

Hello guys,

I've been searching from a week now and still didn't find anything that helped me with this one,

I want to have a vision of my batch numbers and the cost for each item,

Since Power BI's matrix visual has a column limit, I've created a table with 9 rows and ranked my batch numbers by date

If i slice the data by date I has to fill from left to right
The problem is it work only if has one rank from each item
Screenshot_83.pngScreenshot_84.pngScreenshot_82.png

PBIX file:
https://drive.google.com/file/d/1VJxuo9N6GpC8uexMlyk-e8cdDnMYG006/view?usp=sharing

1 ACCEPTED SOLUTION

Hi @WMansueto ,

 

Please try code as below to create [Cost] and [Batch] measures.

Cost = 
VAR _SUMMARIZE =
    SUMMARIZE (
        ALLSELECTED ( Batches ),
        Items[ItemName],
        Batches[BatchNumber],
        Batches[Cost],
        "RANK", [Rank]
    )
VAR _Costs =
    SUMX (
        FILTER (
            _SUMMARIZE,
            [ItemName] = MAX ( Items[ItemName] )
                && [RANK] = MAX ( 'Columns'[IdColumn] )
        ),
        [Cost]
    )
RETURN
    IF ( _Costs = BLANK (), "error", _Costs )
Batch = 
VAR _SUMMARIZE =
    SUMMARIZE (
        ALLSELECTED ( Batches ),
        Items[ItemName],
        Batches[BatchNumber],
        Batches[Cost],
        "RANK", [Rank]
    )
VAR _BatchNumbers =
    MAXX (
        FILTER (
            _SUMMARIZE,
            [ItemName] = MAX ( Items[ItemName] )
                && [RANK] = MAX ( 'Columns'[IdColumn] )
        ),
        [BatchNumber]
    )
RETURN
    IF ( _BatchNumbers = BLANK (), "error", _BatchNumbers )

Result is as below.

By Default:

vrzhoumsft_0-1708940175369.png

With Date filter:

vrzhoumsft_1-1708940186807.png

 

 

Best Regards,
Rico Zhou

 

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

5 REPLIES 5
StrategicSavvy
Resolver II
Resolver II

Hi, 

 

I think that it requires different approach to solve this kind of problem. I would go for calculated column in this specific case as you would like to return information not processing them. 

 

I created calculated column in Batches calles Rank and instead of using measures I would depend on existing + calulated column.  In aggregations it says First batch number but in fact it will be always the one you slice because matrix is operating on the lowest grain - there are no aggregations. 

 

fill column ranks measure.png

 

I attach PBIX.

https://drive.google.com/file/d/1TKXXNAb2xpZoDwMyG5unD_S7eSM0ndLI/view?usp=sharing 

 

 

I hope this post helps to solve your issue and if it does consider accepting it as a solution and giving the post a thumbs up!

My LinkedIn: www.linkedin.com/in/lukasz-kozdron 

 

 

This kind of work but I have to fill the left gaps,
And in my production dashboard i have 100+ batches and the matrix visual is limited to 100 columns,

So, i have to limit only 20 or 30 batches at time.
Screenshot_86.pngScreenshot_87.png

Hi @WMansueto ,

 

Please try code as below to create [Cost] and [Batch] measures.

Cost = 
VAR _SUMMARIZE =
    SUMMARIZE (
        ALLSELECTED ( Batches ),
        Items[ItemName],
        Batches[BatchNumber],
        Batches[Cost],
        "RANK", [Rank]
    )
VAR _Costs =
    SUMX (
        FILTER (
            _SUMMARIZE,
            [ItemName] = MAX ( Items[ItemName] )
                && [RANK] = MAX ( 'Columns'[IdColumn] )
        ),
        [Cost]
    )
RETURN
    IF ( _Costs = BLANK (), "error", _Costs )
Batch = 
VAR _SUMMARIZE =
    SUMMARIZE (
        ALLSELECTED ( Batches ),
        Items[ItemName],
        Batches[BatchNumber],
        Batches[Cost],
        "RANK", [Rank]
    )
VAR _BatchNumbers =
    MAXX (
        FILTER (
            _SUMMARIZE,
            [ItemName] = MAX ( Items[ItemName] )
                && [RANK] = MAX ( 'Columns'[IdColumn] )
        ),
        [BatchNumber]
    )
RETURN
    IF ( _BatchNumbers = BLANK (), "error", _BatchNumbers )

Result is as below.

By Default:

vrzhoumsft_0-1708940175369.png

With Date filter:

vrzhoumsft_1-1708940186807.png

 

 

Best Regards,
Rico Zhou

 

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

 

This works perfectly, thank you so much

lbendlin
Super User
Super User

If you rank them by date then why not include the date in the matrix?

Helpful resources

Announcements
Las Vegas 2025

Join us at the Microsoft Fabric Community Conference

March 31 - April 2, 2025, in Las Vegas, Nevada. Use code MSCUST for a $150 discount!

Dec Fabric Community Survey

We want your feedback!

Your insights matter. That’s why we created a quick survey to learn about your experience finding answers to technical questions.

ArunFabCon

Microsoft Fabric Community Conference 2025

Arun Ulag shares exciting details about the Microsoft Fabric Conference 2025, which will be held in Las Vegas, NV.

December 2024

A Year in Review - December 2024

Find out what content was popular in the Fabric community during 2024.