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
SanKing
Helper I
Helper I

Count of tickets within breakdown (data in two not connected tables)

Dear Power BI Community,

I would like to ask for your help - I have two tables:

Table 1 - with list of tickets & Table 2 - with breakdown time (without aby relation):

SanKing_1-1671454541799.png

Is it possible to count how many tickets were within Breakdown time (from start to end) or mark these tickets?
I tried:

Breakdown tickets? = IF(AND('Table 1'[Ticket Delivery Date]>=MIN('Table 2'[Start]), 'Table 1'[Ticket Delivery Date]<=Max('Table 2'[End])),1,0)
But unfortunately the result it's in 98% 1, exept 3 last days.

Many thanks in advance for any suggestions!
4 ACCEPTED SOLUTIONS
FreemanZ
Super User
Super User

hi @SanKing 

try to add a column in Table2 with this:

DurationCount = 
VAR _start = [Start]
VAR _end =[End]
RETURN
COUNTROWS(
    FILTER(
        Table1,
        Table1[Date]>=_start
            &&Table1[Date]<=_end
    )
)

 

i tried and it worked like this:

FreemanZ_0-1671456082828.png

 

the Table1 sample:

FreemanZ_1-1671456105502.png

 

View solution in original post

Hi @FreemanZ ,
I would like to mark (in new column) in Table 1 if ticket was affected, means 
IF ticket was printed in breakdown time "YES" (or 1), IF not "NO" (or 0).
Formula:
Breakdown tickets? = IF(AND('Table 1'[Ticket Delivery Date]>=MIN('Table 2'[Start]), 'Table 1'[Ticket Delivery Date]<=Max('Table 2'[End])),1,0)
Doesn't work.
Thank you in advance!

View solution in original post

Hi @SanKing ,

If I understand correctly, please try this:

 

Breakdown tickets? = 
VAR _date = 'Table1'[Ticket Delivery Date]
VAR _count = 
COUNTROWS(
    FILTER(
        ALL('Table2'),
        'Table2'[Start]<=_date
        && 'Table2'[End]>=_date
    )
)
VAR _result = 
IF(_count>=1,1,0)
RETURN
_result

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

Hi @SanKing ,

 

Like this?

Breakdown tickets? = 
VAR _date = 'Table1'[Ticket Delivery Date]
VAR _country = 'Table1'[Country]
VAR _count = 
COUNTROWS(
    FILTER(
        ALL('Table2'),
        'Table2'[Country]=_country
        && 'Table2'[Start]<=_date
        && 'Table2'[End]>=_date
    )
)
VAR _result = 
IF(_count>=1,1,0)
RETURN
_result

vcgaomsft_0-1672125131243.png

If I have misunderstood your needs, please feel free to contact me and preferably with expected output.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

View solution in original post

10 REPLIES 10
FreemanZ
Super User
Super User

hi @SanKing 

try to add a column in Table2 with this:

DurationCount = 
VAR _start = [Start]
VAR _end =[End]
RETURN
COUNTROWS(
    FILTER(
        Table1,
        Table1[Date]>=_start
            &&Table1[Date]<=_end
    )
)

 

i tried and it worked like this:

FreemanZ_0-1671456082828.png

 

the Table1 sample:

FreemanZ_1-1671456105502.png

 

Thank you @FreemanZ ,
Works perfectly!
And is there a way to mark each ticket if it was affected?

hi @SanKing 

you are welcom. what does that mean?

Hi @FreemanZ ,
I would like to mark (in new column) in Table 1 if ticket was affected, means 
IF ticket was printed in breakdown time "YES" (or 1), IF not "NO" (or 0).
Formula:
Breakdown tickets? = IF(AND('Table 1'[Ticket Delivery Date]>=MIN('Table 2'[Start]), 'Table 1'[Ticket Delivery Date]<=Max('Table 2'[End])),1,0)
Doesn't work.
Thank you in advance!

hi @SanKing ,What do you mean by don't work? Wrong result or error?

Hi @FreemanZ ,
Unfortunately the results are wrong, it's in 98% 1, exept 3 last days.

Hi @SanKing ,

If I understand correctly, please try this:

 

Breakdown tickets? = 
VAR _date = 'Table1'[Ticket Delivery Date]
VAR _count = 
COUNTROWS(
    FILTER(
        ALL('Table2'),
        'Table2'[Start]<=_date
        && 'Table2'[End]>=_date
    )
)
VAR _result = 
IF(_count>=1,1,0)
RETURN
_result

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Thank you @v-cgao-msft ,
Works perfect, 
Last question - is it possible to add IF parameter for If country from Table1 = Table2?

If I have breakdown in UK, and I don't have breakdown in FR I shouldn't mark tickets from FR.

Thanks in advance!

Hi @SanKing ,

 

Like this?

Breakdown tickets? = 
VAR _date = 'Table1'[Ticket Delivery Date]
VAR _country = 'Table1'[Country]
VAR _count = 
COUNTROWS(
    FILTER(
        ALL('Table2'),
        'Table2'[Country]=_country
        && 'Table2'[Start]<=_date
        && 'Table2'[End]>=_date
    )
)
VAR _result = 
IF(_count>=1,1,0)
RETURN
_result

vcgaomsft_0-1672125131243.png

If I have misunderstood your needs, please feel free to contact me and preferably with expected output.

 

Best Regards,
Gao

Community Support Team

 

If there is any post helps, then please consider Accept it as the solution  to help the other members find it more quickly. If I misunderstand your needs or you still have problems on it, please feel free to let us know. Thanks a lot!

How to get your questions answered quickly --  How to provide sample data in the Power BI Forum

Dear @v-cgao-msft ,

Thank you!

This works perfectly!

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.