Forum Discussion

Anonymous's avatar
Anonymous
Not applicable
8 years ago
Solved

Subtract values based on specific criteria

I'm in a pinch and attempting to get myself through a formula to figure out the differences of two columns, based on specific criteria. This is an audit table, and each item has it's own row every time the item is updated.

 

I'm looking to create two columns, to get two different values but it has to be based on the status. Here is the columns I'm using:

 

 https://imgur.com/a/qCNVdzA

 

What I would like is to be able to subtract:

1. BatchCount when: TrackingIds are the same, AuditReason=Other, RemovalTeamId=7 or 8, and UpdatedBy is = checkin for one value and audit by the second value.

2. UpdateDate when: TrackingIds are the same and UpdatedBy is checkout for one value and checkin for the other value.

 

Thank you!

  • Anonymous's avatar
    Anonymous
    8 years ago

    v-jiascu-msft Thank you! It makes a lot more sense seeing what you did. Also, I think I was on the right track but the column had a lot of null values. That is what was causing the error. I duplicated the whole table, removed the columns I didn't need, filtered out null, then pivoted. Unfortunatley, I'm using DirectQuery and it's telling me that Pivot isn't compatible. So, at least this gets me a little closer because the data looks correct in that I know how I can manipulate it to start extracting what I need from it, like the times. I think I could do the same for BatchCount too. I'll just have to switch everything over to Import and get my gateway setup, and I should be on the right track. Thank you!

10 Replies

  • Anonymous's avatar
    Anonymous
    Not applicable

    I'm in a pinch and attempting to get myself through a formula to figure out the differences of two columns, based on specific criteria. This is an audit table, and each item has it's own row every time the item is updated.

     

    I'm looking to create two columns, to get two different values but it has to be based on the status. Here is the columns I'm using:

     

     https://imgur.com/a/qCNVdzA

     

    What I would like is to be able to subtract:

    1. BatchCount when: TrackingIds are the same, AuditReason=Other, RemovalTeamId=7 or 8, and UpdatedBy is = checkin for one value and audit by the second value.

    2. UpdateDate when: TrackingIds are the same and UpdatedBy is checkout for one value and checkin for the other value.

     

    Thank you!

  • Anonymous's avatar
    Anonymous
    Not applicable

    So you can only do datediff like this on columns.  So what you will likely need to do is pivot that data on the Updated by, so that you would have a column for checkin and Audit, the easy as that you can just datediff the checkin and audit columns

     

     

    **Note, you may need to setup a dataset without those other columns that could be different as they as they would separate your rows.

    • Anonymous's avatar
      Anonymous
      Not applicable

      I think I understand what you're saying, so basically I would need to filter down in to a new table to just the values that I need instead of attempting to filter it out in the larger table?

      • Anonymous's avatar
        Anonymous
        Not applicable

        Kind of, what you really need is a wide table rather then a vertical one.

         

        So instead of having::

        Updatedate     updatedby
        6/19 1:03     checkout
        6/19 1:35     checkin

         

        you would need 
        checkout     checkin
        6/19 1:03    6/19 1:35

  • m_d's avatar
    m_d
    New Member

    I am having similar trouble as a new BI user. I'm trying to calculate session length that is dependent on the variables "action" and "user" or "ip address" to capture distinct sessions. I've tried a few different things but am not having much luck.

     

    Based on this sample data (below) I'd expect that session length calc would result in the following results:

     

    Expected Results:

    DateuserSession Length
    1/1/2022user160 mins
    1/1/2022user2120  mins
    1/2/2022user160 mins
    1/2/2022user2120 mins

     

    Sample data

    UsernameTimeActionIP AddressDate Created
    user11/1/2022 9:15Logout123.45.6781/1/2022
    user11/1/2022 8:45download123.45.6781/1/2022
    user11/1/2022 8:25download123.45.6781/1/2022
    user11/1/2022 8:20download123.45.6781/1/2022
    user11/1/2022 8:15Login123.45.6781/1/2022
    user 21/1/2022 15:15Logout245.543.1231/1/2022
    user 21/1/2022 13:55download245.543.1231/1/2022
    user 21/1/2022 13:25download245.543.1231/1/2022
    user 21/1/2022 13:20download245.543.1231/1/2022
    user 21/1/2022 13:15Login245.543.1231/1/2022
    user11/2/2022 9:15Logout123.45.6781/2/2022
    user11/2/2022 8:45download123.45.6781/2/2022
    user11/2/2022 8:25download123.45.6781/2/2022
    user11/2/2022 8:20download123.45.6781/2/2022
    user11/2/2022 8:15Login123.45.6781/2/2022
    user 21/2/2022 15:15Logout245.543.1231/2/2022
    user 21/2/2022 13:55download245.543.1231/2/2022
    user 21/2/2022 13:25download245.543.1231/2/2022
    user 21/2/2022 13:20download245.543.1231/2/2022
    user 21/2/2022 13:15Login245.543.1231/2/2022

     

    need to isolate distinct users/sessions and then subtract time where action = logout vs login.

     

    greatly appreciate any ideas.