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

Prepping for a Fabric certification exam? Join us for a live prep session with exam experts to learn how to pass the exam. Register 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
Anonymous
Not applicable

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

Anonymous
Not applicable

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
PBIApril_Carousel

Power BI Monthly Update - April 2025

Check out the April 2025 Power BI update to learn about new features.

Notebook Gallery Carousel1

NEW! Community Notebooks Gallery

Explore and share Fabric Notebooks to boost Power BI insights in the new community notebooks gallery.

April2025 Carousel

Fabric Community Update - April 2025

Find out what's new and trending in the Fabric community.

Top Kudoed Authors