The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredEnhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.
Hi,
I want to use a variable to sum different columns of a table in a measure.
Instead of doing:
Solved! Go to Solution.
@Anonymous
This is a good solution given that your dealing with only 12 columns. In cases when you need to deal with un-pivoted data of 50 or 100 columns there is another solution which is way much more complex than yours and won't be feasible in your scenario. I would only simplify the formula as follows:
Daily Budget =
SWITCH (
MONTH ( TODAY () ),
01, SUM ( NetSalesBudget[01] ),
02, SUM ( NetSalesBudget[02] ),
03, SUM ( NetSalesBudget[03] ),
04, SUM ( NetSalesBudget[04] ),
05, SUM ( NetSalesBudget[05] ),
06, SUM ( NetSalesBudget[06] ),
07, SUM ( NetSalesBudget[07] ),
08, SUM ( NetSalesBudget[08] ),
09, SUM ( NetSalesBudget[09] ),
10, SUM ( NetSalesBudget[10] ),
11, SUM ( NetSalesBudget[11] ),
12, SUM ( NetSalesBudget[12] ),
"Error"
)
Hi @Anonymous
The easiest way is to unpivot the table to have one attribute column (equivalent to "index" in your example) and one value column. Not sure if this is a viable possibility in your situation as the formula would be as simple as
CALCULATE (
SUM ( 'Table'[Value] ),
'Table'[Attribute] = "some calculation"
)
Hello,
Thanks for the response but I won't be able to change any of the underlying tables since they must remain as they currently are. I have found a solution:
@Anonymous
This is a good solution given that your dealing with only 12 columns. In cases when you need to deal with un-pivoted data of 50 or 100 columns there is another solution which is way much more complex than yours and won't be feasible in your scenario. I would only simplify the formula as follows:
Daily Budget =
SWITCH (
MONTH ( TODAY () ),
01, SUM ( NetSalesBudget[01] ),
02, SUM ( NetSalesBudget[02] ),
03, SUM ( NetSalesBudget[03] ),
04, SUM ( NetSalesBudget[04] ),
05, SUM ( NetSalesBudget[05] ),
06, SUM ( NetSalesBudget[06] ),
07, SUM ( NetSalesBudget[07] ),
08, SUM ( NetSalesBudget[08] ),
09, SUM ( NetSalesBudget[09] ),
10, SUM ( NetSalesBudget[10] ),
11, SUM ( NetSalesBudget[11] ),
12, SUM ( NetSalesBudget[12] ),
"Error"
)
User | Count |
---|---|
15 | |
11 | |
8 | |
8 | |
7 |
User | Count |
---|---|
21 | |
20 | |
11 | |
10 | |
7 |