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
exodeexo
New Member

max date conditional

Hi guys!!

 

I'd like to create a column (called "MAX_DATE") where I identify the max date in two specific process (PHTM & PHTS) per campaign. If these processes doesn't exist in the campaign, I'd like to asign a null. If one of them exist (PHTM or PHTS), the max_date should be the latest date. As you could see, you could have more than 1 row per campaign and process.

 

AreaProcessStart SequenceCampaign IDMAX_DATE
WHCOD29/07/2015136411null
WHPREP30/07/2015136411null
WHPREP30/07/2015135871null
PRODUCTDESC_IT28/08/2015135871null
WHPREP30/07/201513641113/10/2015
PRODUCTDESC_IT19/08/201513641113/10/2015
PHOTOPHTM13/10/201513641113/10/2015
PHOTOPHTS14/10/201513641114/10/2015
WHPREP19/10/201512786123/10/2015
PHOTOPHTM23/10/201512786123/10/2015
RETOUCHBR2414/10/201512786123/10/2015
RETOUCHPROD14/10/201512786123/10/2015
PHOTOPHTS13/10/201512786123/10/2015
PRODUCTDESC_IT21/10/201512786123/10/2015
PRODUCTUPDATA_IT15/10/201512786123/10/2015
PRODUCTUPDATA_IT19/10/201512786123/10/2015
PHOTOPHTM21/10/201512786123/10/2015

 

I've tried with the following formula, but the result is incorrect because all the campaign ID has date (this is impossible because there are some campaigns without process equals to PHTM or PHTS):

 

 

MAX_DATE = CALCULATE(MAX(Sequencer[Start Sequence].[Date]);Sequencer[Campaign ID];Sequencer[Process]="PHTS";Sequencer[Process]="PHTM")

 

Could you please help me?

 

Many thanks!!

 

Ivann

 

1 ACCEPTED SOLUTION

HI @exodeexo

 

Please try this calculated column

 

New Column = 
    MAXX(
        FILTER(
            'Sequencer',
            'Sequencer'[Process] IN {"PHTS","PHTM"} &&
            'Sequencer'[Campaign ID] = EARLIER('Sequencer'[Campaign ID]) 
            ),
            'Sequencer'[Start Sequence])

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

View solution in original post

11 REPLIES 11
Phil_Seamark
Employee
Employee

Hi @exodeexo

 

Happy to help.  Can you please post what your expected result would look like for this sample dataset?

 

This will help clarify your request 🙂


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Hi @Phil_Seamark!! Thanks for helping me. 

 

My expected result for this sample is the last column on your right.

 

  MAX DATE
null
null
null
null
13/10/2015
13/10/2015
13/10/2015
14/10/2015
23/10/2015
23/10/2015
23/10/2015
23/10/2015
23/10/2015
23/10/2015
23/10/2015
23/10/2015
23/10/2015

 

Many thanks! 

HI @exodeexo

 

Why are the top two rows NULL, when there are other rows for 136411 further down?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Excuse me @Phil_Seamark!

 

I made a mistake, the two first rows should be 13/10/2015 if the campaign id is equals 136411. I've forgotten to change the campaign ID in the two first rows.

Cool, I nearly have it.  Just one more question.

 

On that same campaign 136411, how come all the dates are the 13th, except for the last one which is the 14th of Oct?


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Sorry @Phil_Seamark. It was another mistake that I've modified. The expected result for campaign ID 136411 is 14/10/2015.

 

The correct table:

 

AreaProcessStart SequenceCampaign IDMAX_DATE
WHCOD29/07/2015155555null
WHPREP30/07/2015155555null
WHPREP30/07/2015135871null
PRODUCTDESC_IT28/08/2015135871null
WHPREP30/07/201513641114/10/2015
PRODUCTDESC_IT19/08/201513641114/10/2015
PHOTOPHTM13/10/201513641114/10/2015
PHOTOPHTS14/10/201513641114/10/2015
WHPREP19/10/201512786123/10/2015
PHOTOPHTM23/10/201512786123/10/2015
RETOUCHBR2414/10/201512786123/10/2015
RETOUCHPROD14/10/201512786123/10/2015
PHOTOPHTS13/10/201512786123/10/2015
PRODUCTDESC_IT21/10/201512786123/10/2015
PRODUCTUPDATA_IT15/10/201512786123/10/2015
PRODUCTUPDATA_IT19/10/201512786123/10/2015
PHOTOPHTM21/10/201512786123/10/2015

HI @exodeexo

 

Please try this calculated column

 

New Column = 
    MAXX(
        FILTER(
            'Sequencer',
            'Sequencer'[Process] IN {"PHTS","PHTM"} &&
            'Sequencer'[Campaign ID] = EARLIER('Sequencer'[Campaign ID]) 
            ),
            'Sequencer'[Start Sequence])

To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

This came in very handy for me today.  Thanks for working through this in great detail 2 years ago!

You are a genius,@Phil_Seamark!

 

It works!!! You save me a lot of time!!! Because I've spent all my day trying to solve it!

 

Many thanks!!!!

Happy to help 🙂


To learn more about DAX visit : aka.ms/practicalDAX

Proud to be a Datanaut!

Excuse me @Phil_Seamark

 

The correct table is:

 

AreaProcessStart SequenceCampaign IDMAX_DATE
WHCOD29/07/2015155555null
WHPREP30/07/2015155555null
WHPREP30/07/2015135871null
PRODUCTDESC_IT28/08/2015135871null
WHPREP30/07/201513641114/10/2015
PRODUCTDESC_IT19/08/201513641114/10/2015
PHOTOPHTM13/10/201513641114/10/2015
PHOTOPHTS14/10/201513641114/10/2015
WHPREP19/10/201512786123/10/2015
PHOTOPHTM23/10/201512786123/10/2015
RETOUCHBR2414/10/201512786123/10/2015
RETOUCHPROD14/10/201512786123/10/2015
PHOTOPHTS13/10/201512786123/10/2015
PRODUCTDESC_IT21/10/201512786123/10/2015
PRODUCTUPDATA_IT15/10/201512786123/10/2015
PRODUCTUPDATA_IT19/10/201512786123/10/2015
PHOTOPHTM21/10/201512786123/10/2015

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.