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

Enhance your career with this limited time 50% discount on Fabric and Power BI exams. Ends September 15. Request your voucher.

Reply
gathenjic
Frequent Visitor

How to Assign text value based on dates while the date variable are in 2 different tables

I have 2 tables. Table1 for campaign monitoring which have date_monitored

Table 2: is for campaign calendar - it has Campaign_start_date, Campaign_end_date, Monitoring_start_date and Monitoring_end_date.

 

Monitoring done during campaign is considered as inprocess and after campaign end date its called EndProcess

 

My measure below is meant to Assign the type of monitoring based on dates when monitoring was done. Am however am getting error. I need guidance

 

Type IM = if(MIN('4344_Household Monitoring'[date_monitored])>=MIN('SIAS calendar'[SIAs Start Date]) && MIN('4344_Household Monitoring'[date_monitored])<=MIN('SIAS calendar'[SIAs End Date]),"Inprocess", if(MIN('4344_Household Monitoring'[date_monitored])>=MIN('SIAS calendar'[IM start Date]) && MIN('4344_Household Monitoring'[date_monitored])>=MIN('SIAS calendar'[IM End Date]),"End_process","ERROR"))

16 REPLIES 16
MFelix
Super User
Super User

Hi @gathenjic ,

 

Best option is to create a calendar table to connect both tables and then use that one to make the filtering you need.

 

If you can share a sample data and expected result would be more helpfull to guide you in the right direction.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



@MFelix Thanks for getting intouch to SOLVE

 

How to I attached the .pbix file?

 

 Below is how my table structure looks

 

Table 1: HH-Monitoring - This is the data collection form. Activities are monitored as they happen (Inprocess) and after completion (End_process)

 

Province1District207/02/2020
Province1District208/02/2020
Province1District209/02/2020
Province1District210/02/2020

 

Activity Calendar: Showing dates when Activity started and Ended (inprocess) and dates of post campaign activities

RegionDistrictResponse_TypeActivity_Start_DateActivity_End_DatePost_start_DatePost_End_Date
Province1District1Round 107/02/202011/02/202012/02/202015/02/2020
Province1District2Round 107/02/202011/02/202012/02/202015/02/2020
Province1District3Round 107/02/202011/02/202012/02/202015/02/2020
Province1District4Round 107/02/202011/02/202012/02/202015/02/2020
Province5District5Round 107/02/202011/02/202012/02/202015/02/2020
Province6District6Round 107/02/202011/02/202012/02/202015/02/2020
Province6District7Round 107/02/202011/02/202012/02/202015/02/2020
Province1District1Round 214/03/202018/03/202020/03/202025/03/2020
Province1District2Round 214/03/202018/03/202020/03/202025/03/2020
Province1District3Round 214/03/202018/03/202020/03/2020

25/03/2020

 

Table 3: List of districts for table relationships purpose

PROVINCEDISTRICT
Province1District1
Province1District2
Province1District3
Province1District4
Province5District5
Province6District6
Province6District7


Expectation: To use look at the date of Monitoring against the SIAs calendar and classfy as inprocess, end process otherwise if not within those dates its test data for training

Hi,

 

Could you please tell me that why the column in your formula such as [SIAs Start Date] or [SIAs End Date]does not exist in your sample table?

Please share the expected result as a screenshot for me to help you further.

You can share your pbix file by OneDrive for Business if convenient.

And remember to remove any sensitive data.

Thanks.

 

Best Regards,

Giotto Zhi

@v-gizhi-msft @MFelix 

 

In preparing a sample pbix, I renamed the SIAs start and end date to activity start and End date. In the pbix file shared i have a measure that i was string to create for calculation. maybe it will give more clarity

 

Below is the expected output 

 

https://worldhealthorg-my.sharepoint.com/:u:/g/personal/gathenjic_who_int/Ed9sZ88gRqZInbZAVcSKowABCY...

 

Expected Output: bases on Monitotin_date and Activity dates and IM datesExpected Output: bases on Monitotin_date and Activity dates and IM dates

Hi,

 

It is an incorrect use of IF function that caused error, please try this:

 

TYpe of Monitoring = 
IF (
    MIN ( HH_Monitoring[date_monitored] )
        >= MIN ( 'Activity Calendar'[SIAs_Start_Date] )
        && MIN ( HH_Monitoring[date_monitored] )
            <= MIN ( 'Activity Calendar'[SIAs_End_Date] ),
    "IN_Process",
    IF (
        MIN ( HH_Monitoring[date_monitored] )
            >= MIN ( 'Activity Calendar'[IM_start_Date] )
            && MIN ( HH_Monitoring[date_monitored] )
                <= MIN ( 'Activity Calendar'[IM_End_Date] ),
        "END_Process",
        "TestData"
    )
)

 

The result shows:

1.PNG

 

Best Regards,

Giotto Zhi

@v-gizhi-msft 

 

Thanks That worked, However at the back of my mind i was hoping to be able to use the TYpe of Monitoring in a slicer. This is not working. I Thinks that approach will not work for that.

 

Do you have an idea how i can calculate that measure and be able to use it in a slicer

 

Hi @gathenjic ,

 

Although the answer from @v-gizhi-msft  is absolutly spot on I would use the SWITCH function instead of the IF inside if

 

TYpe of Monitoring =
SWITCH (
    TRUE ();
    MIN ( HH_Monitoring[date_monitored] )
        >= MIN ( 'Activity Calendar'[SIAs_Start_Date] )
        && MIN ( HH_Monitoring[date_monitored] )
            <= MIN ( 'Activity Calendar'[SIAs_End_Date] ); "IN_Process";
    MIN ( HH_Monitoring[date_monitored] )
        >= MIN ( 'Activity Calendar'[IM_start_Date] )
        && MIN ( HH_Monitoring[date_monitored] )
            <= MIN ( 'Activity Calendar'[IM_End_Date] ); "END_Process";
    "TestData"
)

 

To what concerns the last part just create a new table with the 3 states (unrelated table) then create the following measure:

Status Selection = IF(CONTAINS('Status';'Status'[Status];[TYpe of Monitoring]) ;1;0)

Use this measure to filter the table visualization setting the value to equal 1.

 

check PBIX file attach.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi,

 

Please create a table like this by Enter Data:

2.PNG

Then create a check measure:

 

check = IF([TYpe of Monitoring]=SELECTEDVALUE(TypeSlicer[Type]),1,0)

 

Apply this measure to the original visual by setting check=1.

Choose the above [Type] as a slicer, when select one value, the result shows:

3.PNG

 

Best Regards,

Giotto Zhi

@v-gizhi-msft @MFelix 

 

Amazing both dax worked. Great!!!!

 

Am discovering new things as i go.  Here is where I am stuck at, The activity can be repeated in the same district at different dates. How do i make the formular to look into specific dates for that specfiic round

@MFelix @v-gizhi-msft  

 

The measure takes in the start date and end date irresppective of the location (district)The measure takes in the start date and end date irresppective of the location (district)See the marked are the 2 dates that the measure is using to assign IN or END process. My extection is it will evaluate based on the district tooSee the marked are the 2 dates that the measure is using to assign IN or END process. My extection is it will evaluate based on the district too

Hi @gathenjic ,

 

You want the all the lines presented show the same value on the measure or for each one should be a diffenrent value?


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



@MFelix , the Value should differ based on dates supplied on related row in both tables. I think its more about defining how the relationships are and at the same time there is no unique key in either but are related to a master district tabled

 

DistrictResponse_TypeActivity_Start_DateActivity_End_DatePost_start_DatePost_End_Date
District1Round 107/02/202011/02/202012/02/202015/02/2020
District2Round 107/02/202011/02/202012/02/202015/02/2020
District1Round 214/03/202018/03/202020/03/202025/03/2020
District2Round 214/03/202018/03/202020/03/202025/03/2020

 

Provincedistrictdate_monitored
Province1District107/02/2020
Province1District108/02/2020
Province1District209/02/2020
Province1District210/02/2020
Province1District111/02/2020
Province1District114/04/2020
Province1District115/03/2020
Province1District115/03/2020
Province1District216/03/2020
Province1District214/03/2020

Can you please add the result you want on the last table based on the date selection?

 

Thank you


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



Hi @gathenjic ,

 

Measure are calculated based on context so the more values you add to your filters, slicers, visuals an so on the more the result of the measure changes so in this cases if you have the district and province the result will be done with the lowest level of granularity.


Regards

Miguel Félix


Did I answer your question? Mark my post as a solution!

Proud to be a Super User!

Check out my blog: Power BI em Português



@MFelix Is there a way around it to enable get the desired output? 

 

Am open to a new approach too

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.