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

Compete to become Power BI Data Viz World Champion! First round ends August 18th. Get started.

Reply
xxenoss
Helper I
Helper I

All possible date combinations

Hi, I'm trying to solve the trip duratiopn problem

My data looks like this. The first column is the date the train travels to certain destination and returns back the same day.

I need to find all possible trip durations from one point to another for up to 10 days for every date start point and destiantion.

For example:

If I will start my trip from Place_A to Destination_A in the first of May, I can stay at Destination_A for 1, or 3, or 4 days, etc.

If I will start my trip from Place_A to Destination_C in the first of May, I can stay at Destination_C for  2 days, as the next return train is scheduled for the 3rd of May

DateOriginDestination
1-MayPlace_ADestination_A
1-MayPlace_ADestination_C
1-MayPlace_ADestination_B
1-MayPlace_CDestination_B
2-MayPlace_JDestination_B
2-MayPlace_ADestination_A
2-MayPlace_ADestination_B
2-MayPlace_FDestination_B
3-MayPlace_IDestination_A
3-MayPlace_ADestination_D
3-MayPlace_ADestination_C
3-MayPlace_ADestination_B
3-MayPlace_CDestination_B
4-MayPlace_ADestination_A
4-MayPlace_ADestination_B
4-MayPlace_BDestination_A
4-MayPlace_EDestination_B
4-MayPlace_GDestination_B

 

1 ACCEPTED SOLUTION

Hi @xxenoss

Try this measure

Measure =
SWITCH (
    TRUE (),
    [max duration] = 1, 1,
    [max duration] = 2, "1,2",
    [max duration] = 3, "1,2,3",
    [max duration] = 4, "1,2,3,4",
    [max duration] = 5, "1,2,3,4,5",
    [max duration] = 6, "1,2,3,4,5,6",
    [max duration] = 7, "1,2,3,4,5,6,7",
    [max duration] = 8, "1,2,3,4,5,6,7,8",
    [max duration] = 9, "1,2,3,4,5,6,7,8,9",
    [max duration] = 10, "1,2,3,4,5,6,7,8,9,10"
)

16.png

 

 

Best Regards

Maggie

View solution in original post

6 REPLIES 6
v-juanli-msft
Community Support
Community Support

Hi @xxenoss

Create measures

min date =
CALCULATE (
    MIN ( [Date] ),
    FILTER (
        ALL ( Table1 ),
        [Origin] = SELECTEDVALUE ( Table1[Origin] )
            && [Destination] = SELECTEDVALUE ( Table1[Destination] )
    )
)


max date =
CALCULATE (
    MAX([Date])
    FILTER (
        ALL ( Table1 ),
        [Origin] = SELECTEDVALUE ( Table1[Origin] )
            && [Destination] = SELECTEDVALUE ( Table1[Destination] )
    )
)

duration = DATEDIFF([min date],[max date],DAY)+1

12.png

the "duration" is the max days a customer can stays.

 

Best Regards

Maggie

Hi Maggie, 

 

thank you very much for the answer, it was very helpful. But the thing is that I need to store all possible duration from 1 day up to 10. Not sure if it they can be stored in one cell, separated by coma, or in different cells in the sae row.

Hi @xxenoss

Try this measure

Measure =
SWITCH (
    TRUE (),
    [max duration] = 1, 1,
    [max duration] = 2, "1,2",
    [max duration] = 3, "1,2,3",
    [max duration] = 4, "1,2,3,4",
    [max duration] = 5, "1,2,3,4,5",
    [max duration] = 6, "1,2,3,4,5,6",
    [max duration] = 7, "1,2,3,4,5,6,7",
    [max duration] = 8, "1,2,3,4,5,6,7,8",
    [max duration] = 9, "1,2,3,4,5,6,7,8,9",
    [max duration] = 10, "1,2,3,4,5,6,7,8,9,10"
)

16.png

 

 

Best Regards

Maggie

Thank you Maggie, this is brilliant, 

v-juanli-msft
Community Support
Community Support

Hi @xxenoss

trip durations for every date start point and destiantion is detemined by the next return train's schedule, right?

But I can't find the information about the next return train's schedule for each destiantion to start point from your example.

 

Best regards

Maggie 

Hi Maggie,

 

The return date, as I mentioned, is the same with the departure date, for example train starts 1st of May From Place_A to Destination_A in 10:00 in the morning and returns from Destination _A to Place_A at 6:00 in the evening of the same day.

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 Solution Authors