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 August 31st. Request your voucher.

Reply
Tezaroyal
Frequent Visitor

Dax Issue

Hi,

 

I'm trying to show the total nights between the Arrivaldate and depaturedate based on slicer selection 

 

Below is an example. 

The logic behind the Total nights column is the count of nights between the date range that we selected in Slicer is

(7/1/2023- 7/13/2023 ) which I created. For example, Customer A arrived on 7/1/2023 and departed on 7/16/2023. We need to count only the nights which he is staying in between the daterange which we selected in slicer and but not the depature date as he is leaving that day and the total nights are = 13

The number of nights is coming from DB by the logic of the number of nights between arrival and departure date, which is 15 for (Arrived on 7/1/2023 and departure on 7/16/2023). Here we are not counting the night of the departure date as he is leaving the hotel.

Tezaroyal_0-1689607878991.png

 

For Total Night I wrote the measure below. Now I need the sum of total nights on a visual card and but I'm getting blank after draging it into in card . Can someone please help me?  

 

TotalNights_Final = IF(SELECTEDVALUE('report vwRevenueDashboardReport_Data'[ArrivalDate])<[startdate]&&SELECTEDVALUE('report vwRevenueDashboardReport_Data'[DepartureDate])>[enddate], DATEDIFF([startdate],[enddate],DAY)+1,
    IF(SELECTEDVALUE('report vwRevenueDashboardReport_Data'[ArrivalDate])>=[startdate]&& SELECTEDVALUE('report vwRevenueDashboardReport_Data'[DepartureDate])> [enddate],DATEDIFF(SELECTEDVALUE('report vwRevenueDashboardReport_Data'[ArrivalDate]),[enddate],DAY)+1,
    IF(SELECTEDVALUE('report vwRevenueDashboardReport_Data'[ArrivalDate])<[startdate]&&SELECTEDVALUE('report vwRevenueDashboardReport_Data'[DepartureDate])< [enddate],DATEDIFF([startdate],SELECTEDVALUE('report vwRevenueDashboardReport_Data'[DepartureDate]),DAY),
    IF(SELECTEDVALUE('report vwRevenueDashboardReport_Data'[ArrivalDate])>[startdate]&&SELECTEDVALUE('report vwRevenueDashboardReport_Data'[DepartureDate])<[enddate], DATEDIFF(SELECTEDVALUE('report vwRevenueDashboardReport_Data'[ArrivalDate]),SELECTEDVALUE('report vwRevenueDashboardReport_Data'[DepartureDate]),DAY),
    IF(SELECTEDVALUE('report vwRevenueDashboardReport_Data'[ArrivalDate])<=[startdate]&&SELECTEDVALUE('report vwRevenueDashboardReport_Data'[DepartureDate])<[enddate],DATEDIFF([startdate],SELECTEDVALUE('report vwRevenueDashboardReport_Data'[DepartureDate]),DAY),
    IF(SELECTEDVALUE('report vwRevenueDashboardReport_Data'[ArrivalDate])<=[startdate]&&SELECTEDVALUE('report vwRevenueDashboardReport_Data'[DepartureDate])=[enddate],DATEDIFF([startdate],SELECTEDVALUE('report vwRevenueDashboardReport_Data'[DepartureDate]),DAY),
    if(SELECTEDVALUE('report vwRevenueDashboardReport_Data'[ArrivalDate])>[startdate]&&SELECTEDVALUE('report vwRevenueDashboardReport_Data'[DepartureDate])=[enddate],DATEDIFF(SELECTEDVALUE('report vwRevenueDashboardReport_Data'[ArrivalDate]),SELECTEDVALUE('report vwRevenueDashboardReport_Data'[DepartureDate]),DAY),BLANK()
)))))))
1 ACCEPTED SOLUTION
rubayatyasmin
Super User
Super User

HI, @Tezaroyal 

 

You are attempting to create a card visual with this measure, but it is likely returning BLANK because the card visual does not have a row context to reference. This issue arises because a card visual is designed to display single aggregated value (like a sum or an average), and SELECTEDVALUE is not able to work in this context as it returns the value when there's only one value in the specified column for the current filter context, otherwise it returns an alternate result you specify or BLANK() by default.

You may need to revise your measure to handle a situation when multiple or no rows are selected, possibly by replacing SELECTEDVALUE with MIN or MAX, or other suitable aggregate function that would work for your specific case. This would allow you to calculate the total nights even when more than one row is selected.

However, a more effective way could be creating a new table that will create a row for each night a guest stayed and then sum up the rows that fall into the selected slicer dates. This could give you a simple count of rows as a result which could be placed in the card visual.

Remember, without a specific row context, SELECTEDVALUE function will likely not work the way you expect in card visuals.

 

If my assistance helped you in any way, hit 👍

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


View solution in original post

2 REPLIES 2
Greg_Deckler
Community Champion
Community Champion

@Tezaroyal First, please vote for this idea: https://ideas.powerbi.com/ideas/idea/?ideaid=082203f1-594f-4ba7-ac87-bb91096c742e

This looks like a measure totals problem. Very common. See my post about it here: https://community.powerbi.com/t5/DAX-Commands-and-Tips/Dealing-with-Measure-Totals/td-p/63376

Also, this Quick Measure, Measure Totals, The Final Word should get you what you need:
https://community.powerbi.com/t5/Quick-Measures-Gallery/Measure-Totals-The-Final-Word/m-p/547907

Also: https://youtu.be/uXRriTN0cfY
And: https://youtu.be/n4TYhF2ARe8



Follow on LinkedIn
@ me in replies or I'll lose your thread!!!
Instead of a Kudo, please vote for this idea
Become an expert!: Enterprise DNA
External Tools: MSHGQM
YouTube Channel!: Microsoft Hates Greg
Latest book!:
DAX For Humans

DAX is easy, CALCULATE makes DAX hard...
rubayatyasmin
Super User
Super User

HI, @Tezaroyal 

 

You are attempting to create a card visual with this measure, but it is likely returning BLANK because the card visual does not have a row context to reference. This issue arises because a card visual is designed to display single aggregated value (like a sum or an average), and SELECTEDVALUE is not able to work in this context as it returns the value when there's only one value in the specified column for the current filter context, otherwise it returns an alternate result you specify or BLANK() by default.

You may need to revise your measure to handle a situation when multiple or no rows are selected, possibly by replacing SELECTEDVALUE with MIN or MAX, or other suitable aggregate function that would work for your specific case. This would allow you to calculate the total nights even when more than one row is selected.

However, a more effective way could be creating a new table that will create a row for each night a guest stayed and then sum up the rows that fall into the selected slicer dates. This could give you a simple count of rows as a result which could be placed in the card visual.

Remember, without a specific row context, SELECTEDVALUE function will likely not work the way you expect in card visuals.

 

If my assistance helped you in any way, hit 👍

 

rubayatyasmin_0-1689517080227.png


Did I answer your question? Mark my post as a solution!super-user-logo

Proud to be a Super User!


Helpful resources

Announcements
July 2025 community update carousel

Fabric Community Update - July 2025

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

July PBI25 Carousel

Power BI Monthly Update - July 2025

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