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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Huei
Frequent Visitor

Count Measure Values

Hi Guys,

 

I need help, 

 

Below are my current result

 

CustomerNameStatusSalesAmountPY SalesAmount
Customer 1Growing167,08849,588
Customer 2New34,4700.00
Customer 3New5,4000.00
Customer 4Growing11,191436.62
Customer 5Declining1,16427,775

 

1 ) Calculated Sales Amount using measure 

Sales Amt = CALCULATE(SUM(Sellout[Total Selling]),TREATAS(VALUES(Budget[Brand]),Sellout[BRAND]))+0
 
2) Calculated PY Sales Amount using measure 
PY Sales Amt = CALCULATE([Sales Amt],SAMEPERIODLASTYEAR(Dates[Date].[Date]))
 
3) Status (if else) using measure
Status =
IF(
[Sales Amt]<> 0 && [PY Sales Amt] <> 0 && [Sales Amt]>[PY Sales Amt],
"Growing",
IF(
[Sales Amt]<>0 && [PY Sales Amt]<>0 && [Sales Amt]<[PY Sales Amt],
"Declining",
IF(
([Sales Amt])<>0 && [PY Sales Amt]=0 ,
"New",
IF(
[Sales Amt]=0 && [PY Sales Amt]<>0,
"Lost","-"
))))
 
Question
-----------
How can i calculate the 'Status'? i want to count How many status in Growing, Declining & New
 
Anyone can please advice?
 
Thanks
1 ACCEPTED SOLUTION

"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")

 

View solution in original post

11 REPLIES 11
Huei
Frequent Visitor

Hi Ibendlin,

 

It's worked, thankyou so much! Appreciate.

 

 

Glad to hear.   Just to reiterate - you cannot count measure values. You need to formulate the business requirement and then write another measure that implements the associated logic.

 

Also note that my first measure is not fully covering all scenarios. (for example when both current and previous year values are blank). Adjust as needed.

Huei
Frequent Visitor

Okay, noted. I will check first measure. But i still having problem here, i change to use calculated column for TY sales amount and PY sales amount, but the PY Sales amount show blank. Can you please advise?

 

Thanks.

"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")

 

Huei
Frequent Visitor

Because yesterday the first measure you advise was referring to table column. That's why i changed to used calculated column. 

 

var t= calculate(sum('Table'[SalesAmount]))
var p= CALCULATE(sum('Table'[PY SalesAmount]))

 

But the latest calculated column version solved my problem.

 

Many Thanks!! 

 

Huei
Frequent Visitor

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.

Huei
Frequent 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?

Not really, you need a separate measure for that. (It is the recommended approach anyway).

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.

lbendlin
Super User
Super User

Just to confirm - you want this all as measures?  (it would be easier as calculated columns).

 

You are also missing the scenario when the two values match.

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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