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

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.

Reply
CarlsBerg999
Helper V
Helper V

Selectedvalues when nothing is selected

Im trying to get a count of weeks since 1.3.2021 from my datetable. However, if the user clicks visuals, it should count how many weeks the user has selected. The DAX code below works, when the user has selected weeks from a visual (For example, activated week1 and week2). However, it returns blank if no weeks are selected. How do i get the formula to return weeks since 1.3.2021, if no week selection is made? It tried adding another filter (= DateTable[Date] >= DATE("2021","3","1"))) But it did not produce the expected result.
 
Weeks Since 1.3.2021 = CALCULATE(DISTINCTCOUNT(DateTable[Week & Week Name]),
FILTER(DateTable,DateTable[WeekName]=SELECTEDVALUE(DateTable[WeekName])))


3 REPLIES 3
v-shex-msft
Community Support
Community Support

Hi @CarlsBerg999,

Can you please share some dummy data with a similar data structure and expected results? It should help us clarify your scenario and test to coding formula.

How to Get Your Question Answered Quickly  

Regards,

Xiaoxin Sheng

Community Support Team _ Xiaoxin
If this post helps, please consider accept as solution to help other members find it more quickly.
Jihwan_Kim
Super User
Super User

Hi, @CarlsBerg999 

Please correct me if I wrongly understood.

 

If readers do not select anything in the slicer, you want to show XXXXXX.

In this case, could you please try below?

 

 

Weeks Since 1.3.2021 =
If( isfiltered(DateTable),
CALCULATE(DISTINCTCOUNT(DateTable[Week & Week Name]),
FILTER(DateTable,DateTable[WeekName]=SELECTEDVALUE(DateTable[WeekName]))),
XXXXXX)
 
I hope it helps.
 
Did I answer your question? Mark my post as a solution! Appreciate your Kudos!!

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


amitchandak
Super User
Super User

@CarlsBerg999 , Check with allselected

 

Weeks Since 1.3.2021 = CALCULATE(DISTINCTCOUNT(DateTable[Week & Week Name]),
FILTER(DateTable,DateTable[WeekName] in allselected(DateTable[WeekName])))

 

 

or

 

Weeks Since 1.3.2021 =

var _max  = maxx(allselected(DateTable),DateTable[WeekName])

return

CALCULATE(DISTINCTCOUNT(DateTable[Week & Week Name]),
FILTER(DateTable,DateTable[WeekName] = _max))

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

Check out the April 2024 Power BI update to learn about new features.

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors