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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends August 31st. Request your voucher.

Reply
MegaOctane1
Helper I
Helper I

compare store sales per article, to other stores of the same size (std. dev, average)

Hi guys,

I have a table in excel where i calculate Average, Max and Standard deviation.
So what i want to do is:

Compare the current stores sale of each article to other stores that are same in size. This works in Excel, but we want to replicate this to Power BI. I want to create a table visual in Power BI to show the data


Average has the formula: =AVERAGE(FILTER([Qty];([StoreSize]=[@StoreSize]) * ([Store]<>[@Store]) * ([Article]=[@Article])))
Max: =MAX(FILTER([Qty];[Store]=[@Store]))
Std dev: =STDEV.P(FILTER([Qty];([StoreSize]=[@StoreSize]) * ([Store]<>[@Store]) * ([Article]=[@Article])))

ArticleStoreStoreSizeMonthQtyAverageMaxStd dev
5604554001smalljan.252,001,6720,94
5604554001smallfeb.251,001,6720,94
5604554002smalljan.251,00 EA1,5030,50
5604554002smallfeb.253,00 EA1,5030,50
5604554002smallmar.251,00 EA1,5030,50
5715124003mediumjan.252,001,0040,00
5715124003mediumfeb.254,001,0040,00
5715124004smalljan.252,00 EA5,5041,50
5715124004smallfeb.254,00 EA5,5041,50
5715124004smallmar.251,00 EA5,5041,50
5715124004smallapr.252,00 EA5,5041,50
5715124005smallfeb.257,00 EA2,2571,09
5715124005smallapr.254,00 EA2,2571,09
5715124006mediumjan.251,00 EA3,0011,00
5715124006mediumfeb.251,00 EA3,0011,00
5715124006mediummar.251,00 EA3,0011,00
5715124006mediumapr.251,00 EA3,0011,00
1 ACCEPTED SOLUTION

Hi @MegaOctane1,

I made small tweak to the measures now it is working fine. Also I am attching .pbix file for your reference. I update the measures in original/intitial responce post.

ajaybabuinturi_0-1749194270726.png

 

Here is the .pbix file.

https://drive.google.com/file/d/16dFidVfzLkrNnHzvhUbM4UJy_VYgmmNs/view 

 

Thanks,
If you found this solution helpful, please consider giving it a Like👍 and marking it as Accepted Solution✔. This helps improve visibility for others who may be encountering/facing same questions/issues.

 

View solution in original post

10 REPLIES 10
v-ssriganesh
Community Support
Community Support

Hi @MegaOctane1,
Thank you for reaching out to the Microsoft Fabric Forum Community.

I have reproduced your scenario in Power BI Desktop and achieved the expected output as per your requirement. For your reference, I’m attaching the .pbix file that contains the complete implementation, including the Z-Score calculation logic and formatted table output.

If this information is helpful, please “Accept as solution” and give a "kudos" to assist other community members in resolving similar issues more efficiently.
Thank you.

lmolus
Advocate II
Advocate II

Hi, 

try this:

VAR _article = MAX( 'Table'[Article] ) 
VAR _store= MAX( 'Table'[Store] )
VAR _storesize = MAX( 'Table'[StoreSize] )
VAR Result = 
CALCULATE( 
    AVERAGE( 'Table'[Sales] ) , 
    FILTER( 
        ALL( 'Table'[Article] , 'Table'[Store] , 'Table'[StoreSize] ) , 
        'Table'[Article] = _article 
            && 'Table'[StoreSize] = _storesize
            && 'Table'[Store] <> _store
    )
)
RETURN
    Result

 

It should work, you can calculate ST.DEV. and MAX using simillar approach.

I tried with the sample data i provided. The calculation when used in a table view, returns blanks

MeasureMAX = 
VAR _article = MAX( 'tblSales'[Article] ) 
VAR _store= MAX( 'tblSales'[Store] )
VAR _storesize = MAX( 'tblSales'[StoreSize] )
VAR Result = 
CALCULATE( 
    AVERAGE( 'tblSales'[Delivered] ) , 
    FILTER( 
        ALL( 'tblSales'[Article] , 'tblSales'[Store] , 'tblSales'[StoreSize] ) , 
        'tblSales'[Article] = _article 
            && 'tblSales'[StoreSize] = _storesize
            && 'tblSales'[Store] <> _store
    )
)
RETURN
    Result

 

My data shows blank:

image.png

 

 

Here is a link to sample data:
https://www.dropbox.com/scl/fi/oqdurfcgeywydrtdjd15w/Sample_data.xlsx?rlkey=b6d1610mw70m2hzb9j9oyo20...

Do you have any relationships in your semantic model, that might be used in a table (from your screen)?

It would be much easier if you could send a .pbix file with sample data.

ajaybabuinturi
Solution Sage
Solution Sage

Hi @MegaOctane1,

Can you try with below formula. Let me know if you have any questions.

AvgQty_OtherStores = 
CALCULATE(
    AVERAGE(Sales[Delivered]),
    FILTER(
        ALL(Sales),
        Sales[StoreSize] = SELECTEDVALUE(Sales[StoreSize]) &&
        Sales[Store] <> SELECTEDVALUE(Sales[Store]) &&
        Sales[Article] = SELECTEDVALUE(Sales[Article])
    )
)
MaxQty_CurrentStore = 
CALCULATE(
    MAX(Sales[Delivered]),
    FILTER(
        ALL(Sales),
        Sales[Store] = SELECTEDVALUE(Sales[Store]) &&
        Sales[Article] = SELECTEDVALUE(Sales[Article])
    )
)
StdDevQty_OtherStores = 
CALCULATE(
    STDEV.P(Sales[Delivered]),
    FILTER(
        ALL(Sales),
        Sales[StoreSize] = SELECTEDVALUE(Sales[StoreSize]) &&
        Sales[Store] <> SELECTEDVALUE(Sales[Store]) &&
        Sales[Article] = SELECTEDVALUE(Sales[Article])
    )
)
Max # Std from Avrg1 = 
DIVIDE((Sales[MaxQty_CurrentStore] - Sales[AvgQty_OtherStores]), Sales[StdDevQty_OtherStores], BLANK())

 

  • Ensure your data model is not filtering out relevant data via slicers or relationships. The SELECTEDVALUE functions rely on proper row context.
  • If your model has separate dimension tables (for stores, articles), you might need to adjust context using RELATED or TREATAS.

Thanks,
If you found this solution helpful, please consider giving it a Like👍 and marking it as Accepted Solution✔. This helps improve visibility for others who may be encountering/facing same questions/issues.

Hi and thank you for a quick reply.
I tried the first formula, and it didn't work unfortunately. it returns blank on all lines

@MegaOctane1 Could you please provide some sample data.

Here is sample data in Excel. i have also attached the formulas we are using.

 

https://www.dropbox.com/scl/fi/oqdurfcgeywydrtdjd15w/Sample_data.xlsx?rlkey=b6d1610mw70m2hzb9j9oyo20...

Hi @MegaOctane1,

I made small tweak to the measures now it is working fine. Also I am attching .pbix file for your reference. I update the measures in original/intitial responce post.

ajaybabuinturi_0-1749194270726.png

 

Here is the .pbix file.

https://drive.google.com/file/d/16dFidVfzLkrNnHzvhUbM4UJy_VYgmmNs/view 

 

Thanks,
If you found this solution helpful, please consider giving it a Like👍 and marking it as Accepted Solution✔. This helps improve visibility for others who may be encountering/facing same questions/issues.

 

PERFECT!!!!

Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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