Forum Discussion

ricod's avatar
ricod
Helper I
1 year ago

Variation IN and OUT

Hello

 

i've a folder with xslx files containing cat and dog names. i want from 1st september 2024 calculate the variation of placements. i've tried many thinks with date table or not but i'm not able to do it specially when i filter with type (dog or cat)

 

can you help ?

 

xlsx file(s)

typearrivaldeparture
dog01/01/202502/01/2025
cat01/01/202501/02/2025
dog02/01/202502/02/2025
dog02/01/202502/02/2025
dog04/01/2025 
dog04/01/2025 
dog04/01/2025 
dog04/01/2025 
dog03/01/202403/02/2025
dog03/01/202403/02/2025

 

output expected (with possibility to filter on type cat, dog, ... ) :

dateINOUTvariation
Jan. 2025211
feb. 2025230
mar. 202502-2
apr. 2025402

 

What i've done but it's not ok

 

 

14 Replies

  • Hello ricod ,

     

    1- Create a DateTable.

    DateTable = CALENDAR(MIN(YourData[arrival]), MAX(YourData[departure]))

    You can add column to DateTable:

    Month = FORMAT(DateTable[Date], "mmm yyyy")
    Year = YEAR(DateTable[Date])

     

    2- Create IN measure that counts all arrivals for each month

    IN = 
    CALCULATE(
        COUNTROWS(YourData),
        YourData[arrival] <= MAX(DateTable[Date]),
        YourData[arrival] > MIN(DateTable[Date])
    )

    Create OUT measure that counts all departures for each month

    OUT = 
    CALCULATE(
        COUNTROWS(YourData),
        YourData[departure] <= MAX(DateTable[Date]),
        YourData[departure] > MIN(DateTable[Date])
    )

    Create Variation measure

    Variation = [IN] - [OUT]

    3- Final output should be like this:

    Month	        IN	OUT	Variation
    Jan. 2025	2	1	1
    Feb. 2025	2	3	0
    Mar. 2025	0	2	-2
    Apr. 2025	4	0	4

     

    If that helps, please accept as a solution!

    Thank you.

    • ricod's avatar
      ricod
      Helper I

      the april result is not correct, should be 2

       

       

       

      • anilelmastasi's avatar
        anilelmastasi
        Super User

        Could you write this formula?

        Variation = 
        VAR CurrentMonth = MAX(DateTable[Date])
        RETURN
        SUMX(
            FILTER(
                ALL(DateTable),
                DateTable[Date] <= CurrentMonth
            ),
            [IN] - [OUT]
        )
  • Fowmy's avatar
    Fowmy
    Super User

    ricod 

    Create a dates table and a relationship.

    Add these measures:

    IN = 
    
    COUNTROWS(
        FILTER(
            Table01,
            Table01[arrival] >= MIN(Dates[Date]) &&
            Table01[arrival] <= MAX(Dates[Date])
        )
    )

     

    OUT = 
    
    COUNTROWS(
        FILTER(
            Table01,
            Table01[departure] >= MIN(Dates[Date]) &&
            Table01[departure] <= MAX(Dates[Date])
        )
    )

     

    Variance  = [IN] - [Out]
  • Anonymous's avatar
    Anonymous
    Not applicable

    Hi ricod ,

    Did the above suggestions help with your scenario? if that is the case, you can consider Kudo or Accept the helpful suggestions to help others who faced similar requirements.

    If these also don't help, please share more detailed information and description to help us clarify your scenario to test.

    How to Get Your Question Answered Quickly 

    Regards,

    Xiaoxin Sheng

    • ricod's avatar
      ricod
      Helper I

      hi, 

      it's not ok, i've only one raw with arrival and departure date. so it's not what expected

      • Ashish_Mathur's avatar
        Ashish_Mathur
        Super User

        So based on the picure in my previous post, what result are you expecting?