Forum Discussion

marri's avatar
marri
Frequent Visitor
8 years ago

Data filtering using multiple date columns of a table

Hi,

 

I need some approaches on the below. I have a tabular model with the table called proposals and

Suppose table proposals have different date columns like initiationdate, responsedate, completeddate.

I will consider calendar table for the date prompt in report

And I have date range filter in report where user prompts Fromdate and Todate

 

Now when a user selects the range in date fitler in powerbi report, the records to be displayed on the visual is from the table proposals with the multiple conditions like where initiationdate between the date range selected in date filter

or responsedate between the date range selected in date filter 

or completeddate between the date range selected in date filter

productidinitiationdateresponsedatecompleteddate
1276/5/20176/9/20176/13/2018
1286/6/20176/10/20176/14/2018
1296/7/20176/15/20176/19/2018
1306/8/20176/16/20176/20/2018
1316/9/20176/17/20176/21/2018
1326/10/20176/18/20176/22/2018
1336/16/20176/19/20176/23/2018
1346/17/20176/20/20176/24/2018
1356/18/20176/21/20176/25/2018
1366/19/20176/22/20176/26/2018
1376/20/20176/23/20176/27/2018
1386/21/20176/24/20176/28/2018

 

date prompt 
FromTo
6/7/20176/14/2017

 

Expected Output:  
productidinitiationdateresponsedatecompleteddate
1276/5/20176/9/20176/13/2018
1286/6/20176/10/20176/14/2018
1296/7/20176/15/20176/19/2018
1306/8/20176/16/20176/20/2018
1316/9/20176/17/20176/21/2018
1326/10/20176/18/20176/22/2018

Please let me know the approach/ideas how shall i design the model and come up with the query

 

Thanks

3 Replies

  • v-jiascu-msft's avatar
    v-jiascu-msft
    Microsoft Employee

    Hi marri,

     

    Two approaches here. You can download the demo and try it out.

    1. Add a measure and filter the values of the measure. (No relationship between two tables.)

    Measure =
    VAR initdate =
        MIN ( Table1[initiationdate] )
    VAR respdate =
        MIN ( Table1[responsedate] )
    VAR comdate =
        MIN ( Table1[completeddate] )
    RETURN
        IF (
            (
                initdate >= MIN ( 'Date Prompt'[Date] )
                    && initdate <= MAX ( 'Date Prompt'[Date] )
            )
                || (
                    respdate >= MIN ( 'Date Prompt'[Date] )
                        && respdate <= MAX ( 'Date Prompt'[Date] )
                )
                || (
                    comdate >= MIN ( 'Date Prompt'[Date] )
                        && comdate <= MAX ( 'Date Prompt'[Date] )
                ),
            1,
            0
        )

    2. Unpivot the table Proposals. (relationship to Date table is needed.)

    Data_filtering_using_multiple_date_columns_of_a_table

     

    Best Regards,

    Dale

     

    • marri's avatar
      marri
      Frequent Visitor

      Thankyou for the reply.

      I have tried the same way as mentioned in your approach 1( without relationship between time(calendar) and proposals table)

      But could not able to see the expected result.

      Please find the below screen shot

       

      Always Measure displays the value with "0" even though the product_sid's initiationdate, responsedate, completedate falls within the range of date prompt. For example, please verify for the product_sid 35659008, 35659015. The formula which is used is mentioned below

      Measure  = VAR initiationdate = MIN(proposals[initiationdate]) VAR responsedate = MIN(proposals[responsedate]) VAR completedate = MIN(proposals[completedate])  RETURN IF (
              (
                  initiationdate >= MIN ( 'time'[Date] )
                      && initiationdate<= MAX ( 'time'[Date] )
              )
                  || (
                      proposeddate>= MIN ( 'time'[Date])
                          && proposeddate<= MAX ( 'time'[Date])
                  )
                  || (
                      completedate >= MIN ( 'time'[Date])
                          && completedate <= MAX ( 'time'[Date] )
                  ),
              1,
        0
          )

       

      Please help me in understanding why does always  measure shows the value 0 instead of displaying 1 even for the records which falls into the date range prompt.

       

       

      Approach2:

      Proposals table is very large data set with minimum of 16 millions of records. Does unpivot of table proposals and having the relationship with time table works? Please clarify.

       

       

      • v-jiascu-msft's avatar
        v-jiascu-msft
        Microsoft Employee

        Hi marri,

         

        Did you try out the demo I shared? Can you share your pbix file? It should work.

         

        Best Regards,

        Dale