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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
sujit_Shirke
New Member

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.

 
1 ACCEPTED SOLUTION

@sujit_Shirke 
Please find the file attached.
https://drive.google.com/file/d/1dEKygfkYa-omPEodTfcsuu1Agj0mW9Rw/view?usp=share_link


If 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



View solution in original post

11 REPLIES 11
Dinesh_Suranga
Continued Contributor
Continued Contributor

Hi @sujit_Shirke ,
Get the XDays as return of your dax. then you can see what it feeds to the function.

 

Thanks

Dinesh

Its return which i selected in Slicer 

Hi @sujit_Shirke ,

What is the data format of XDays column.
Thanks
Dinesh

Whole Number

tharunkumarRTK
Super User
Super User

Can you share the pbix file with sample data?

Its not allowing to send sample pbix

@sujit_Shirke 
upload the file to your gdrive and share the link

@sujit_Shirke 

In your file you created a caculated table, A calcualted table is static and it cannot capture the seclections made in the slicer even if you use selectedvalue function. Incase if you want to count the number of customers according to the selections in the slicer then create a measure and use countrows function. 

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
countrows( CustomersNotOrdering)


Or if you want to see the customer list according to then one of the patter that you can use is:

Customers Not Ordering in Last X Days = 
VAR XDays = SELECTEDVALUE(Xday[Xday], 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
IF(SELECTEDVALUE(Sales[Customer] ) in CustomersNotOrdering, 1, 0) 

and put filters to remove 0.

 


If 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

 

no luck

@sujit_Shirke 
Please find the file attached.
https://drive.google.com/file/d/1dEKygfkYa-omPEodTfcsuu1Agj0mW9Rw/view?usp=share_link


If 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



Helpful resources

Announcements
August Power BI Update Carousel

Power BI Monthly Update - August 2025

Check out the August 2025 Power BI update to learn about new features.

August 2025 community update carousel

Fabric Community Update - August 2025

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

Top Kudoed Authors