Forum Discussion

awff's avatar
awff
Helper III
2 years ago
Solved

Getting max values if date is between date column from another table

Hi there!

 

I am creating a report from usage log files where I have tabulated the values.

 

I have created two tables, one is a Product Log/History table which shows what each customer has and the number of licenses in the period. The other is the usage log which is simple when they log in to use the product.

 

Basically, I need to show if the number of users has exceeded their license count for the product in each session (day). 

 

For example...

 

This is a product table:

Product VersionCustomerNameStartDateLicenses
A1Customer 11/01/20231
B1Customer 11/01/20232
C1Customer 11/01/20235
B2Customer 116/05/20232
A3Customer 116/05/202310
B3Customer 14/09/20232
C3Customer 14/09/20235
D3Customer 14/09/20235

 

This is the Usage Log table

SessionStartCustomerNameProductUser
1/02/2023Customer 1AAndrew
1/02/2023Customer 1AJohn
1/02/2023Customer 1BAndrew
1/02/2023Customer 1ABob
1/02/2023Customer 1ABob
1/02/2023Customer 1AJane
1/02/2023Customer 1CJane
1/02/2023Customer 1CJane
1/02/2023Customer 1AAndrew
6/06/2023Customer 1CSam
6/06/2023Customer 1CSam
6/06/2023Customer 1CSam
6/06/2023Customer 1CSam
6/06/2023Customer 1ABob
6/06/2023Customer 1AJane

 

Just looking at Product A... [StartDate] is 1/01/2023 and has 1 license and the next update is 16/05/2023 when they upgraded to 16 licenses. So between 1/01/2023 to 15/05/2023 there is only 1 license available. 

 

In the Usage Log, for the session 1/02/2023 is between 1/01/2023 to 15/05/2023 so they should only have one license. How can I create either a measure or a calculated column to show the max licenses from the Product Log?

 

Ideally I can use this as a constant line in a chart to show periods where the customer has exceeded their license count.

 

Thanks!

 

  • Found a solution:

    In the product table I needed to get the end date for each product in the same row with a calculated col:

    SessionNextUpdate =
    Var FromDate = 'ProductLog'[SessionStart]
    VAR Customer = 'ProductLog'[Customer]
    VAR Product = 'ProductLog'[Product]
    VAR res =
    CALCULATE(
        MIN('ProductLog'[SessionStart]),
        FILTER(
            'ProductLog',
            'ProductLog'[Product] = Product &&
            'ProductLog'[Customer] = Customer &&
            'ProductLog'[SessionStart] > FromDate)
    )
    RETURN
    SWITCH(
        TRUE(),
        res = blank(), DATE(9999,12,31), res1)

    Then in the Usage Log, another calculated column:

    MaxLicenses =
    maxx(
        FILTER(
            'ProductLog',
            'UsageLog'[Customer] = 'ProductLog'[Customer] &&
            'UsageLog'[Product] = 'ProductLog'[Product] &&
            'UsageLog'[SessionStart] >= 'ProductLog'[SessionStart] &&
            'UsageLog'[SessionStart] <= 'ProductLog'[SessionNextUpdate]
            ),
        'ProductLog'[Licenses]
    )

4 Replies

  • awff's avatar
    awff
    Helper III

    I'm not sure how to attach a pbix file as a sample here, but here is a sample dataset:

     

    Usage Log:

     

    SessionStartCustomerNameProductUser
    1/02/2023Customer 1AAndrew
    1/02/2023Customer 1AJohn
    1/02/2023Customer 1BAndrew
    1/02/2023Customer 1ABob
    1/02/2023Customer 1ABob
    1/02/2023Customer 1AJane
    1/02/2023Customer 1CJane
    1/02/2023Customer 1CJane
    1/02/2023Customer 1AAndrew
    6/06/2023Customer 1CSam
    6/06/2023Customer 1CSam
    6/06/2023Customer 1CSam
    6/06/2023Customer 1CSam
    6/06/2023Customer 1ABob
    6/06/2023Customer 1AJane
    6/06/2023Customer 1ASam
    6/06/2023Customer 1ABob
    6/06/2023Customer 1BBob
    23/05/2023Customer 2DTim
    23/05/2023Customer 2DTim
    23/05/2023Customer 2DSteven
    23/05/2023Customer 2AJames
    23/05/2023Customer 2CJames
    23/05/2023Customer 2CJames
    1/01/2023Customer 3AJack
    1/01/2023Customer 3BJack
    31/05/2023Customer 3AJack
    7/12/2023Customer 3BJack

     

    Product Log:

    Product VersionCustomerNameStartDateLicenses
    A1Customer 11/01/20231
    B1Customer 11/01/20232
    C1Customer 11/01/20235
    B2Customer 116/05/20232
    A3Customer 116/05/202310
    B3Customer 14/09/20232
    C3Customer 14/09/20235
    D3Customer 14/09/20235
    B1Customer 29/07/20232
    C1Customer 29/07/20236
    A2Customer 230/11/20235
    B3Customer 230/11/20235
    C3Customer 230/11/20235
    D3Customer 230/11/20235
    A1Customer 31/03/20231
    A2Customer 320/05/202310
    A2Customer 31/12/202315
    B3Customer 35/12/20233
  • awff 

    As per your description, Product A license got upgarded to 11 Licenses (1+10), not 16. 
    According to the log, Product A has beeen used by three users (Andrew, Jane and Bob) between 1/1/2023 to 15/1/2023. Therefor excceded by 2. Is this what you need?

    • awff's avatar
      awff
      Helper III

      Hi Fowmy, hope you had a good weekend. The product data only provides the current total licenses for each new period. In this case:

       

      from 1/01/2023 to 15/05/2023 the customer had only 1 license.

      from 16/05/2023  onwards (or next update) the customer has a total of 10 licenses.

       

      Your second statement about license usage is correct. Even if I can get a link to the two tables to show the max licenses held if the Usage SessionStart date falls between the product log dates.

       

       

  • awff's avatar
    awff
    Helper III
    Found a solution:

    In the product table I needed to get the end date for each product in the same row with a calculated col:

    SessionNextUpdate =
    Var FromDate = 'ProductLog'[SessionStart]
    VAR Customer = 'ProductLog'[Customer]
    VAR Product = 'ProductLog'[Product]
    VAR res =
    CALCULATE(
        MIN('ProductLog'[SessionStart]),
        FILTER(
            'ProductLog',
            'ProductLog'[Product] = Product &&
            'ProductLog'[Customer] = Customer &&
            'ProductLog'[SessionStart] > FromDate)
    )
    RETURN
    SWITCH(
        TRUE(),
        res = blank(), DATE(9999,12,31), res1)

    Then in the Usage Log, another calculated column:

    MaxLicenses =
    maxx(
        FILTER(
            'ProductLog',
            'UsageLog'[Customer] = 'ProductLog'[Customer] &&
            'UsageLog'[Product] = 'ProductLog'[Product] &&
            'UsageLog'[SessionStart] >= 'ProductLog'[SessionStart] &&
            'UsageLog'[SessionStart] <= 'ProductLog'[SessionNextUpdate]
            ),
        'ProductLog'[Licenses]
    )