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
Anonymous
Not applicable

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!

2 ACCEPTED SOLUTIONS

Hi @Anonymous,

 

Please check out the demo in the attachment.

1. Select these two columns with "CTRL";

2. Pivot.

Subtract_values_based_on_specific_criteria2

 

Best Regards,

Dale

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

Anonymous
Not applicable

@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!

View solution in original post

10 REPLIES 10
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.

 

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
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
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
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

Anonymous
Not applicable

Yeah, actually, that makes it really easy. I was able to run these sorts of stats in an older version of this database last year, and that's how it was formatted. This is normalized in sort of an 'audit' table but it doesn't make it easy for comparison of updates to each 'record'. Now I just have to figure out how to transpose the data like this. Don't think I'll get it in time for today like I was hoping, but at least this helps going forward. Thank you for the help!

Hi @Anonymous,

 

Is it something as follows?

Subtract_values_based_on_specific_criteria

 

Best Regards,

Dale

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

@v-jiascu-msft

 

Whoa!!! That's it!! And to go even further, it would be awesome to be able to string everything down the same row - like differing batch counts too. But this gets me much closer to what I was looking for.

 

How exactly do I go about doing this? I see the pivot, but I keep getting an error if I attempt to pivot based on either UpdateDate or UpdatedBy

Hi @Anonymous,

 

Please check out the demo in the attachment.

1. Select these two columns with "CTRL";

2. Pivot.

Subtract_values_based_on_specific_criteria2

 

Best Regards,

Dale

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

@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!

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.