Forum Discussion

sujit_Shirke's avatar
sujit_Shirke
New Member
2 years ago
Solved

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.

 

11 Replies