The ultimate Fabric, Power BI, SQL, and AI community-led learning event. Save €200 with code FABCOMM.
Get registeredCompete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.
I have a customer sales table of 2018 and 2019 sales only. The Sales Date has a relationship to a DATE dimension table. I am trying to write a DAX measure will give me a count of distinct Customer ShipTo numbers for those customers who made a purchase in 2019 but not 2018. I'm trying to follow DAX code patterns that are decribed in various blog entries by several well know DAX programmers. Below is my code. There is no error when creating the measure. But when I add it to a visual I get the error:
'A table of multiple values was supplied when a single value was expected'
I'm not sure where the problem is since CALCULATE is being asked to return a scalar. Any help is appreciated.
Solved! Go to Solution.
DATESBETWEEN is returning a list of dates and you are not applying any aggregation over it, you can use this.
Acquired Customers =
CALCULATE (
COUNTROWS ( VALUES ( VwCOPA[ShipTo] ) ),
EXCEPT (
VALUES ( VwCOPA[ShipTo] ),
CALCULATETABLE (
VALUES ( VwCOPA[ShipTo] ),
FILTER (
ALL ( 'Date'[Date] ),
'Date'[Date] > DATE ( 2008, 1, 1 )
&& 'Date'[Date] < DATE ( 2008, 12, 31 )
),
ALL ( 'Date'[Date] )
)
)
)
HI @Anonymous ,
Acquired Customers :=
COUNTROWS (
FILTER (
ADDCOLUMNS (
VALUES ( VwCOPA[ShipTo] ),
"PreviousPurchase", CALCULATE (
COUNTROWS ( VwCOPA ),
FILTER (
ALL ( VwCOPA ),
Date[Year] = 2018
)
),
"CurrentPurchase", CALCULATE (
COUNTROWS ( VwCOPA ),
FILTER (
ALL ( VwCOPA ),
Date[Year] = 2019
)
)
),
[PreviousPurchase] = 0
&& [CurrentPurchase] <> 0
)
Regards,
Harsh Nathani
Thanks for your reply Lbendin. I was using <> CALCULATEDTABLE because I found that construct in this article (in the second code listing there for Acquired Customers):
https://javierguillen.wordpress.com/2012/08/24/determining-customer-retention-in-dax/
I have re-written my code using the EXCEPT function as per below. But, like my first code, it shows no errors when i create it but when I add it to a visual I get the same error of: 'A table of multiple values was supplied when a single value was expected'.
HI @Anonymous ,
Acquired Customers :=
COUNTROWS (
FILTER (
ADDCOLUMNS (
VALUES ( VwCOPA[ShipTo] ),
"PreviousPurchase", CALCULATE (
COUNTROWS ( VwCOPA ),
FILTER (
ALL ( VwCOPA ),
Date[Year] = 2018
)
),
"CurrentPurchase", CALCULATE (
COUNTROWS ( VwCOPA ),
FILTER (
ALL ( VwCOPA ),
Date[Year] = 2019
)
)
),
[PreviousPurchase] = 0
&& [CurrentPurchase] <> 0
)
Regards,
Harsh Nathani
DATESBETWEEN is returning a list of dates and you are not applying any aggregation over it, you can use this.
Acquired Customers =
CALCULATE (
COUNTROWS ( VALUES ( VwCOPA[ShipTo] ) ),
EXCEPT (
VALUES ( VwCOPA[ShipTo] ),
CALCULATETABLE (
VALUES ( VwCOPA[ShipTo] ),
FILTER (
ALL ( 'Date'[Date] ),
'Date'[Date] > DATE ( 2008, 1, 1 )
&& 'Date'[Date] < DATE ( 2008, 12, 31 )
),
ALL ( 'Date'[Date] )
)
)
)
Thanks Antriksh. This makes sense now!
John
Hi @Anonymous ,
Have a look at the video for customer churn analysis
https://www.youtube.com/watch?v=h9kRwgamLcw
Regards,
HN
Thanks Harshnathani. This is helpful. As I sift through all the ways to use the various functions, and all the possible code patterns, I know I need to settle on the most optimal ones. I think some of the code patterns I have found online are now rather old. I will experiment with what you have shown.
I don't think this part
User | Count |
---|---|
28 | |
10 | |
8 | |
6 | |
5 |
User | Count |
---|---|
33 | |
13 | |
12 | |
9 | |
7 |