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
Anonymous
Not applicable

Getting value from latest given time each day

Hi Experts,

 

I need your help. I would like to create a measure to get the last checked-in value for each day.  The data model and expected output is shown below. Please helpTimeQuery.png

 

Thanks

1 ACCEPTED SOLUTION
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may keep the Cross filter direction of relationships between the tables above in Both, then you can create measure like DAX below.

 

Measure =

Var d=CALCULATE(MAX('Fact_Tourist arrived'[TimeKey]),ALLEXCEPT('Fact_Tourist arrived','Fact_Tourist arrived'[Hotel Key],'Fact_Tourist arrived'[DateKey]))

Return

CALCULATE(SUM('Fact_Tourist arrived'[No. of Tourist arrived]),FILTER(ALLSELECTED('Fact_Tourist arrived'),'Fact_Tourist arrived'[TimeKey]=d&&'Fact_Tourist arrived'[Hotel Key]=MAX('Fact_Tourist arrived'[Hotel Key])&&'Fact_Tourist arrived'[DateKey]=MAX('Fact_Tourist arrived'[DateKey])))

 

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

View solution in original post

4 REPLIES 4
v-xicai
Community Support
Community Support

Hi @Anonymous ,

 

You may keep the Cross filter direction of relationships between the tables above in Both, then you can create measure like DAX below.

 

Measure =

Var d=CALCULATE(MAX('Fact_Tourist arrived'[TimeKey]),ALLEXCEPT('Fact_Tourist arrived','Fact_Tourist arrived'[Hotel Key],'Fact_Tourist arrived'[DateKey]))

Return

CALCULATE(SUM('Fact_Tourist arrived'[No. of Tourist arrived]),FILTER(ALLSELECTED('Fact_Tourist arrived'),'Fact_Tourist arrived'[TimeKey]=d&&'Fact_Tourist arrived'[Hotel Key]=MAX('Fact_Tourist arrived'[Hotel Key])&&'Fact_Tourist arrived'[DateKey]=MAX('Fact_Tourist arrived'[DateKey])))

 

Best Regards,

Amy 

 

Community Support Team _ Amy

If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Anonymous
Not applicable

Thanks @Amy
It worked.
amitchandak
Super User
Super User

@Anonymous 

Try like


Measure =
VAR __id = MIN ( 'Table'[Datetime] )
VAR __date = CALCULATE ( MIN( 'Table'[Datetime] ), ALLSELECTED ( 'Table' ), 'Table'[hotelname] = __id )
RETURN CALCULATE ( sum ( 'Table'[tourist arrived] ), VALUES ( 'Table'[hotelname] ),values('Date'[Date]), 'Table'[hotelname] = __id, 'Table'[Datetime] = __date )

 

If does not work share some sample data

Mariusz
Community Champion
Community Champion

Hi @Anonymous 

 

Try this,

Measure = 
VAR __maxTime = 
    GROUPBY( 
        'Table', 
        'Hotel'[Hotel Name],
        'Date'[Date], 
        "@maxTime", MAXX( CURRENTGROUP(), 'Table'[Time] )
    )
RETURN 
CALCULATE(
    SUM( 'Table'[No of Tourist ] ),
    TREATAS( __maxTime, 'Hotel'[Hotel Name], 'Date'[Date], 'Table'[Time] )
)

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

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.