Forum Discussion
Help with DAX ALLSelected
Hi Team,
I need some help with writing dax formula. PFB details.
My data model is having 2 tables and the data modelling as below . My datasource is a combination of live and direct query.
DimProduct:
| Product | Product Key |
| Apple | 1 |
| Banana | 2 |
| Orange | 3 |
| Mango | 4 |
FactSales:
| ProductForeignKey | Amount |
| 1 | 10 |
| 1 | 10 |
| 2 | 20 |
| 3 | 30 |
| 4 | 40 |
| 4 | 40 |
So i would like to take product key, product foreign key into table visual and dispaly the total sum of amount (150) againist each row by using ALLSelected function as below.
Please help with this, any help is very much appreciated.
Thanks.
6 Replies
- Daniel29195Community Champion
All Amount = CALCULATE(SUM(FactSales[Amount]),ALLSELECTED(dimproduct[productname]))If this answers your question , mark it as the solution ā so can you can help other people in the community find it easily .
- Vamshi_PBIFrequent Visitor
Hi Daniel29195 ,
With this approach , cross join wont happen, but total sum (for selected products or all products) is not reflected for all rows.
Thanks.
- Daniel29195Community Champion
if you are intending of using all the product columns into the visual :
All Amount = CALCULATE(SUM(FactSales[Amount]),ALLSELECTED(dimproduct))
- AnonymousNot applicable
Hi Vamshi_PBI
Your problem may be related to using the ALLSELECTED function in DirectQuery mode.
One possible solution is to use the KEEPFILTERS function instead of ALLSELECTED. The KEEPFILTERS function preserves the existing filters in the filter context and applies them to the specified column or table. For example, you can create a new measure like this:
All Amount = CALCULATE( SUM(FactSales[Amount]), KEEPFILTERS(FactSales) )If you still have problems, it's best to provide the pbix file with your expected results and be careful to remove sensitive data.
Regards,
Nono Chen
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.