Forum Discussion
Count Measure Values
- 4 years ago
"i change to use calculated column"
Why? I thought your goal was to do everything with measures?
Here is the formula for the calculated column version:
Column Group = SWITCH(TRUE(), ISBLANK([PY SalesAmount]) && ISBLANK([SalesAmount]),"Inactive", ISBLANK([PY SalesAmount]) && not ISBLANK([SalesAmount]),"New", not ISBLANK([PY SalesAmount]) && ISBLANK([SalesAmount]),"Lost", [SalesAmount]>[PY SalesAmount],"Increasing", [SalesAmount]<[PY SalesAmount],"Declining", "Same")
Hi Ibendlin,
I'm New in Power BI. If use calculated columns meaning all measures change to calculated columns for Sales amount, PY Sales amount and status?
Thanks
Calculated columns are only computed once during dataset refresh. Measures are recomputed each time the user interacts with the report. More flexibiliy, at the expense of more compute.
- Huei4 years agoFrequent Visitor
I had tried to use calculated columns for all the measure, but the result was wrong that's why i use all measure. Can i count the measure?
- lbendlin4 years ago
Super User
Not really, you need a separate measure for that. (It is the recommended approach anyway).
- lbendlin4 years ago
Super User
Here is the first measure:
Group = var t= calculate(sum('Table'[SalesAmount])) var p= CALCULATE(sum('Table'[PY SalesAmount])) return if(HASONEVALUE('Table'[CustomerName]),switch(TRUE(), ISBLANK(t),"Lost",ISBLANK(p),"New",t>p,"Growing",p>t,"Declining","Same"))Here is the second measure:
Customers = var s = SELECTEDVALUE(Groups[Group]) var a = ADDCOLUMNS(VALUES('Table'[CustomerName]),"TY",calculate(sum('Table'[SalesAmount])),"PY",calculate(sum('Table'[PY SalesAmount]))) var b = ADDCOLUMNS(a,"Match",SWITCH(TRUE(), s="Lost" && not ISBLANK([PY]) && ISBLANK([TY]),1, s="New" && not ISBLANK([TY]) && ISBLANK([PY]),1, s="Declining" && not ISBLANK([TY]) && not ISBLANK([PY]) && [TY]<[PY],1, s="Growing" && not ISBLANK([TY]) && not ISBLANK([PY]) && [TY]>[PY],1, s="Same" && not ISBLANK([TY]) && not ISBLANK([PY]) && [TY]=[PY],1, 0)) return if(hasonevalue(Groups[Group]),sumx(b,[Match]))See attached.