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.
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 @Datazen ,
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 @Datazen ,
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 @Datazen ,
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
Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City
Check out the April 2024 Power BI update to learn about new features.
User | Count |
---|---|
47 | |
24 | |
20 | |
15 | |
13 |
User | Count |
---|---|
51 | |
46 | |
39 | |
19 | |
19 |