Forum Discussion
SelectedValue function not Working
Hello,
I have a table named Sales with two columns: InvoiceDate and Customer. I want to retrieve a list of customers who have not placed orders within a selected number of days, compared to the same number of days prior.
For instance, if today is March 20th, I want to identify customers who placed orders between March 11th and March 20th, and then compare this with their order history between March 1st and March 10th. Customers who ordered between March 1st and March 10th but not between March 11th and March 20th should be included in the list.
To achieve this, I created a parameter named "Days" with a data type of Whole Number and a range of values from 1 to 30.
I created a table using the following DAX formula to retrieve the list of customers:
```DAX
Customers Not Ordering in Last X Days =
VAR XDays = SELECTEDVALUE(Days[XDays], 30) // Default to 30 if no value is selected
VAR PeriodStart = TODAY() - XDays
VAR CustomersWithOrders = CALCULATETABLE(
DISTINCT(Sales[Customer]),
Sales[InvoiceDate] >= PeriodStart // Changed the equality sign to greater than or equal to
)
VAR PreviousDays = PeriodStart - XDays
VAR AllCustomers = CALCULATETABLE(
DISTINCT(Sales[Customer]),
Sales[InvoiceDate] < PeriodStart,
Sales[InvoiceDate] >= PreviousDays // Changed the equality sign to less than
)
VAR CustomersNotOrdering = EXCEPT(AllCustomers, CustomersWithOrders)
RETURN
CustomersNotOrdering
```
I'm using the parameter as a slicer, but when I select values using the slicer, the formula does not seem to work. However, when I hardcode the value of `XDays`, the formula works fine. Even `VAR XDays = SELECTEDVALUE(Days[XDays], 30)` only works with the default value.
I appreciate any assistance with resolving this issue. Thank you.
sujit_Shirke
Please find the file attached.
https://drive.google.com/file/d/1dEKygfkYa-omPEodTfcsuu1Agj0mW9Rw/view?usp=share_linkIf the post helps please give a thumbs up
If it solves your issue, please accept it as the solution to help the other members find it more quickly.
Tharun
11 Replies
- tharunkumarRTKSuper User
Can you share the pbix file with sample data?
- sujit_ShirkeNew Member
Its not allowing to send sample pbix
- tharunkumarRTKSuper User
sujit_Shirke
upload the file to your gdrive and share the link
- Dinesh_SurangaContinued Contributor
Hi sujit_Shirke ,
Get the XDays as return of your dax. then you can see what it feeds to the function.Thanks
Dinesh
- sujit_ShirkeNew Member
Its return which i selected in Slicer
- Dinesh_SurangaContinued Contributor
Hi sujit_Shirke ,
What is the data format of XDays column.
Thanks
Dinesh