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
Simnati
Regular Visitor

sum of measures by grouping measures

Hello Everyone,

 

I have been struggling for the last fews days trying to sum numbers of night spent per reservation number.

Let me try to be the more precise on my explanation.

here is my data

 DATA.png

 

I am trying to count the exact number of night spent between filtered date. 

For example : 

I have a total night spent for reservation A in room 100 of 32 nights. But If I put a filter date of dates between 01.01.2018 and 31.01.2018 , I have 30 nights.

So I have created the following measure to dynamically calculate my min date and max date based on my date filters.

 

var minday=
CALCULATE(
DATEVALUE(MIN('Reservations-Mews'[Column1.StartUtc]));all('Calendar');FILTER('Reservations-Mews';DATEVALUE('Reservations-Mews'[Column1.StartUtc])<=DATEVALUE(LASTDATE('Calendar'[Date]))&& DATEVALUE('Reservations-Mews'[Column1.EndUtc])>= DATEVALUE(FIRSTDATE('Calendar'[Date]))))
return
var maxday=
CALCULATE(
DATEVALUE(max('Reservations-Mews'[Column1.EndUtc]));all('Calendar');FILTER('Reservations-Mews';DATEVALUE('Reservations-Mews'[Column1.StartUtc])<=LASTDATE('Calendar'[Date])&& DATEVALUE('Reservations-Mews'[Column1.EndUtc])>= FIRSTDATE('Calendar'[Date])))
return
 
Then I have calculated the amounts of night spent within the filtered date , and I have created this measure to have it dynamically:
var days_passed=

CALCULATE(


DATEDIFF(

if(
DATEVALUE(minday)<DATEVALUE(FIRSTDATE('Calendar'[Date]));
DATEVALUE(FIRSTDATE('Calendar'[Date]));if(
DATEVALUE(minday)=DATEVALUE(LASTDATE('Calendar'[Date]));DATEVALUE(LASTDATE('Calendar'[Date]));DATEVALUE(minday)));
 
 
if(
 
DATEVALUE(maxday)>DATEVALUE(LASTDATE('Calendar'[Date]));
DATEVALUE(LASTDATE('Calendar'[Date]))+1;if(
DATEVALUE(maxday)=DATEVALUE(FIRSTDATE('Calendar'[Date]));DATEVALUE(FIRSTDATE('Calendar'[Date]));DATEVALUE(maxday)))
 
;DAY))



return
 
Until that point, everyhting is perfect.....but this is when a simple things get's so complicated that I need your help please!!!!!!!
 
Instead of summing all the nights spend per room, it is applying the rule of getting the min date during the period and the max date during periode .
 
Example: Date filter is between 01.01.2018 (included) and 31.01.2018(included)
Total of nights spent for reservation A : 
Room 100 has 30 nights and room 101 has 6 nights.
So total of nights spent should be 36
 
But instead it is showing 30 nights, because the min date of reservation A is 01.01.2018 and max date of reservation A is 02.02.2018 ( corrected to 31.01.2018, due to my measure called minday), and the DATEDIFF between this two dates is 30 days.
DATA2.png
 
So I have went trough all bunch of topics , that talks about SUMMARIZE, GROUPBY, SUMX.....but nothing works!!!! When I try Sumx it multiplies everything even the wrong total. Please I need your help
1 REPLY 1
CheenuSing
Community Champion
Community Champion

Hi @Simnati ,

 

Have you found a solution to this ? 

 

If not please share the pbix on google / share drive and paste the link here.  Also clearly state the value expected .

 

Cheers

 

CheenuSing 

Did I answer your question? Mark my post as a solution and also give KUDOS !

Proud to be a Datanaut!

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.