Search code examples
powerbidaxdata-analysispowerbi-desktopmeasure

Stopping a Power BI Table visual slicing the result of a virtual table


I'm trying to do some min max scaling in Power BI to give turn values into scaled scores between 0 and 1. To do this, i need to first calculate the minimum and maximum values. However, i'm struggling to get this to work on aggregated data in a visual.

For example i've got counts of individual shops at a given geography (city in the example) and I want to get the minimum count at city-level in order to assess how a given city compares.

My table visual brings the shop-level data into a table with City as the first column. Any time though i try and calculate a city-level minimum, the table visual cuts the data by City, so it only reflects the context of each single city.

Is there a way of approaching this other than creating a proper summary table at aggregated level and working from that? I've resisted this so far as in theory i'd like to also drill down from city to street level.

The following seems to work as intended on it's own (in a Card) but if i put it in a table visual it splits the data by City again and only reflects the City at row level. I've tried things like ALL('Data'), ALLSELECTED('Data'[City]) etc but can't override the visual slicing it.

Thanks

Min Count of G rated by City = 
--Virtual table summarised by City
VAR Virt_Summary = 
    SUMMARIZE(
        'Data',
        'Data'[City],  
        "TotalCount",
        CALCULATE(
            COUNTROWS('Data'),
            'Data'[Rating] = "G"
        )
    )
--Get the min value of the aggregated virtual table
VAR MinValue = 
CALCULATE(
    MAXX(Virt_Summary, [TotalCount]),
    ALL('Data')  // Remove all filters
)

RETURN MinValue

Solution

  • Have you got your ALL() in the correct place?

    Min Count of G rated by City = 
    --Virtual table summarised by City
    VAR Virt_Summary = 
        SUMMARIZE(
            ALL('Data'),
            'Data'[City],  
            "TotalCount",
            CALCULATE(
                COUNTROWS('Data'),
                'Data'[Rating] = "G"
            )
        )
    --Get the min value of the aggregated virtual table
    VAR MinValue = 
    
        MAXX(Virt_Summary, [TotalCount])
    
    
    RETURN MinValue