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
mturcotte
Frequent Visitor

Generating Text Labels in Column for "Current Campaign" or past Campaign Start and End Dates

Hi,

My customer has 4 marketing campaigns per year with the following dates:

  • January 1st through April 30th
  • May 1st through June 30th
  • July 1st through September 30th
  • October 1st through December 31st.

So to illustrate my current problem, I created an example Campaigns report with 2 dates tables:

CampaignCalendar = CALENDAR(DATE(2018,01,01),DATE(2019,12,31))

 

Transactions = CALENDAR(DATE(2018,01,01),DATE(2019,07,31))

 

And inside CampaignCalendar, I created these addition columns:

CampaignStart =

   SWITCH( MONTH([Date]),

           1, DATEVALUE(YEAR([Date])&"-01-01"),

           2, DATEVALUE(YEAR([Date])&"-01-01"),

           3, DATEVALUE(YEAR([Date])&"-01-01"),

           4, DATEVALUE(YEAR([Date])&"-01-01"),

           5, DATEVALUE(YEAR([Date])&"-05-01"),

           6, DATEVALUE(YEAR([Date])&"-05-01"),

           7, DATEVALUE(YEAR([Date])&"-07-01"),

           8, DATEVALUE(YEAR([Date])&"-07-01"),

           9, DATEVALUE(YEAR([Date])&"-07-01"),

           10, DATEVALUE(YEAR([Date])&"-10-01"),

           11, DATEVALUE(YEAR([Date])&"-10-01"),

           12, DATEVALUE(YEAR([Date])&"-10-01")

   )

 

CampaignEnd =

   SWITCH( MONTH([Date]),

           1, DATEVALUE(YEAR([Date])&"-04-30"),

           2, DATEVALUE(YEAR([Date])&"-04-30"),

           3, DATEVALUE(YEAR([Date])&"-04-30"),

           4, DATEVALUE(YEAR([Date])&"-04-30"),

           5, DATEVALUE(YEAR([Date])&"-06-30"),

           6, DATEVALUE(YEAR([Date])&"-06-30"),

           7, DATEVALUE(YEAR([Date])&"-09-30"),

           8, DATEVALUE(YEAR([Date])&"-09-30"),

           9, DATEVALUE(YEAR([Date])&"-09-30"),

           10, DATEVALUE(YEAR([Date])&"-12-31"),

           11, DATEVALUE(YEAR([Date])&"-12-31"),

           12, DATEVALUE(YEAR([Date])&"-12-31")

   )

 

LstTx after CampaignStart = MAX('Transactions'[Date]) >= [CampaignStart]

 

LstTx before CampaignEnd = MAX('Transactions'[Date]) <= [CampaignEnd]

 

And finally, I created the following DAX code to generate text labels for the Campaign Choice column:

Campaign Choice =

   IF(

       [CampaignEnd] <= MAX('Transactions'[Date]), --Campaign End Date for current date precedes Last Transaction Date

       IF(

           AND( CampaignCalendar[LstTx after CampaignStart], --Campaign Start Date for current date precedes Last Transaction Date

                 CampaignCalendar[LstTx before CampaignEnd]   --Campaign End Date for current date greater than Last Transaction Date

           ),

           "Current Campaign", -- Last Transaction Date is between Start and End Campaign Dates of current one (YET NOT OUTPUT WHEN EXPECTED)

           "( " & FORMAT([CampaignStart],"yyyy-MM-dd") & " - " & FORMAT([CampaignEnd],"yyyy-MM-dd") & " )"

       ),

       BLANK() --Campaign End Date for current date greater than Last Transaction Date ==> DO NOT OFFER THIS CAMPAIGN YET

   )

 

My problem is that I am not getting “Current Campaign” for dates between July 1st and September 30th even though the columns “LstTx after CampaignStart” and “LstTx before CampaignEnd” are BOTH TRUE. For the other rows, I am getting what I need (either blank for future campaigns, or Start and End Dates for past campaigns).

Here’s a link to a screenshot showing what I’m getting:

https://1drv.ms/u/s!ArclD4PLnaKAnw7U7v6pc1eI70SQ?e=7eWZUk

Here’s link to my report:

https://1drv.ms/u/s!ArclD4PLnaKAnw7U7v6pc1eI70SQ?e=7eWZUk

Any idea what I’m doing wrong or missing?

Thanks,

MT

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

@mturcotte 

 

The first expression is evaluated to FALSE.

[CampaignEnd] <= MAX('Transactions'[Date])

 

 

Community Support Team _ Sam Zha
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

1 REPLY 1
v-chuncz-msft
Community Support
Community Support

@mturcotte 

 

The first expression is evaluated to FALSE.

[CampaignEnd] <= MAX('Transactions'[Date])

 

 

Community Support Team _ Sam Zha
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

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.

Top Solution Authors