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

Earn a 50% discount on the DP-600 certification exam by completing the Fabric 30 Days to Learn It challenge.

Reply
svendaems
Frequent Visitor

Find previous and next date

Hi,

I hope somebody can help me with this setup I want to achieve in PowerBI. 

 

I've 2 tables, a table tblServers & a table tblWaves. The tblServers lists out all servers & to which wave they belong. The tabel tblWaves gives for each wave some dates. Sometimes a wave only occures each quarter, some waves are more frequently (wave3 in this example). There's a one to many relationship between those 2 tables.

 

svendaems_0-1714740884679.png

 

I want to show on my dashboard on what date the previous wave took place & when the next wave will take place, depending on todays date. So in this example (today is May 3rd) it would give this example.

svendaems_2-1714741388960.png

 

Anybody an idea how to crack this one?

1 ACCEPTED SOLUTION
v-junyant-msft
Community Support
Community Support

Hi @svendaems ,

Thanks for your concern about this case!
@svendaems Have you solved your problem? If not, please try this way:
Because today is not May 3rd, so I use May 3rd to test:

Previous Patching = 
VAR PatchingName = tblPatching[Name]
VAR RelatedWave = RELATED(tblServers[Wave])
VAR TargetDate = CALCULATE(
    MINX(
        FILTER(
            tblWaves,
            tblWaves[Wave] = RelatedWave &&
            tblWaves[Date] <= DATE(2024, 5, 3)
        ),
        tblWaves[Date]
    ),
    ALL(tblWaves)
)
RETURN TargetDate
Next Patching = 
VAR PatchingName = tblPatching[Name]
VAR RelatedWave = RELATED(tblServers[Wave])
VAR TargetDate = CALCULATE(
    MINX(
        FILTER(
            tblWaves,
            tblWaves[Wave] = RelatedWave &&
            tblWaves[Date] >= DATE(2024, 5, 3)
        ),
        tblWaves[Date]
    ),
    ALL(tblWaves)
)
RETURN TargetDate

vjunyantmsft_0-1715579921250.png

Please change the 

DATE(2024, 5, 3)

into

TODAY()


Best Regards,
Dino Tao
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

6 REPLIES 6
v-junyant-msft
Community Support
Community Support

Hi @svendaems ,

Thanks for your concern about this case!
@svendaems Have you solved your problem? If not, please try this way:
Because today is not May 3rd, so I use May 3rd to test:

Previous Patching = 
VAR PatchingName = tblPatching[Name]
VAR RelatedWave = RELATED(tblServers[Wave])
VAR TargetDate = CALCULATE(
    MINX(
        FILTER(
            tblWaves,
            tblWaves[Wave] = RelatedWave &&
            tblWaves[Date] <= DATE(2024, 5, 3)
        ),
        tblWaves[Date]
    ),
    ALL(tblWaves)
)
RETURN TargetDate
Next Patching = 
VAR PatchingName = tblPatching[Name]
VAR RelatedWave = RELATED(tblServers[Wave])
VAR TargetDate = CALCULATE(
    MINX(
        FILTER(
            tblWaves,
            tblWaves[Wave] = RelatedWave &&
            tblWaves[Date] >= DATE(2024, 5, 3)
        ),
        tblWaves[Date]
    ),
    ALL(tblWaves)
)
RETURN TargetDate

vjunyantmsft_0-1715579921250.png

Please change the 

DATE(2024, 5, 3)

into

TODAY()


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

Thanks @v-junyant-msft , this is exactly what I needed

 

Thanks also @Greg_Deckler  for helping me

Greg_Deckler
Super User
Super User

@svendaems Try:

Previous Patching = 
  VAR __Today = TODAY()
  VAR __Result = MAXX(FILTETER('tblWaves', [Date] <= __Today), [Date])
RETURN
  __Result

Next Patching = 
  VAR __Today = TODAY()
  VAR __Result = MINX(FILTETER('tblWaves', [Date] >= __Today), [Date])
RETURN
  __Result

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler 

 

Thanks already for your reply. Unfortunlatly it's not working out as it should. It isn't looking at the related server, but giving for all servers the same date. It takes the first date that matches the formula (first previous date or first next date, related to today).

 

svendaems_0-1714746945891.png

 

@svendaems Can you post your data as text? I also don't understand how you have a 1 to many relationship between those two tables. This *may* be it::

Previous Patching = 
  VAR __Today = TODAY()
  VAR __Wave = MAX('tblServers'[Wave])
  VAR __Result = MAXX(FILTETER('tblWaves', [Wave] = __Wave && [Date] <= __Today), [Date])
RETURN
  __Result

Next Patching = 
  VAR __Today = TODAY()
  VAR __Result = MINX(FILTETER('tblWaves', [Wave] = __Wave && [Date] >= __Today), [Date])
RETURN
  __Result

@ 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!:
The Definitive Guide to Power Query (M)

DAX is easy, CALCULATE makes DAX hard...

Hi @Greg_Deckler 

 

You're right, I made a mistake in my question. It's a many to many relationship. I've added the data in a test pbx file, you can download it here.

 

I've tried also your second suggestion but that gives the same result.

svendaems_0-1715001201329.png

 

Helpful resources

Announcements
LearnSurvey

Fabric certifications survey

Certification feedback opportunity for the community.

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.