Forum Discussion

krishnavzm's avatar
krishnavzm
Frequent Visitor
3 years ago
Solved

How to display total cost value based on two date values

Hi, I'm new to Power BI. Trying to create a report based on the data available from 2020- 2023. Please find the beow sample data.

Item code   Dispatch date  Estimated Cost  Arrival Date  Actual Cost 
I-0017/1/20221008/1/2022200
I-0027/4/20222008/4/2022300
I-0038/23/20223009/3/2022400
I-0048/24/20224009/20/2022500
I-0059/1/20225009/9/2022600
I-0069/2/202260010/2/2022700

 

From the above table , can you help me to generate chart on monthly basis. 1.Need to Display Total Actual cost / Monthly and 2. Total Estimated cost / Monthly . End User will select Year and Month as a filter option. Both 1 and 2 should be in same chart.

 

Thank you for your help

  • Hi, krishnavzm 

     

    You can try the following methods. Divide your sample data into 2 tables.

    Table1:

    Table2:

    New Table:

    Date = CALENDAR(MIN('Table 1'[Dispatch Date]),MAX('Table 2'[Arrival Date]))

    Column:

    Year = YEAR([Date])
    Month = MONTH([Date])

    Measure:

    Total Actual cost / Monthly =
    CALCULATE (
        SUM ( 'Table 2'[Actual Cost] ),
        FILTER (
            ALL ( 'Date' ),
            [Year] = SELECTEDVALUE ( 'Date'[Year] )
                && [Month] = SELECTEDVALUE ( 'Date'[Month] )
        )
    )
    
    Total Estimated cost / Monthly =
    CALCULATE (
        SUM ( 'Table 1'[Estimated Cost] ),
        FILTER (
            ALL ( 'Date' ),
            [Year] = SELECTEDVALUE ( 'Date'[Year] )
                && [Month] = SELECTEDVALUE ( 'Date'[Month] )
        )
    )
    

    Result:

    Is this the result you expect?

    Best Regards,

    Community Support Team _Charlotte

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

2 Replies

  • v-zhangti's avatar
    v-zhangti
    Community Support

    Hi, krishnavzm 

     

    You can try the following methods. Divide your sample data into 2 tables.

    Table1:

    Table2:

    New Table:

    Date = CALENDAR(MIN('Table 1'[Dispatch Date]),MAX('Table 2'[Arrival Date]))

    Column:

    Year = YEAR([Date])
    Month = MONTH([Date])

    Measure:

    Total Actual cost / Monthly =
    CALCULATE (
        SUM ( 'Table 2'[Actual Cost] ),
        FILTER (
            ALL ( 'Date' ),
            [Year] = SELECTEDVALUE ( 'Date'[Year] )
                && [Month] = SELECTEDVALUE ( 'Date'[Month] )
        )
    )
    
    Total Estimated cost / Monthly =
    CALCULATE (
        SUM ( 'Table 1'[Estimated Cost] ),
        FILTER (
            ALL ( 'Date' ),
            [Year] = SELECTEDVALUE ( 'Date'[Year] )
                && [Month] = SELECTEDVALUE ( 'Date'[Month] )
        )
    )
    

    Result:

    Is this the result you expect?

    Best Regards,

    Community Support Team _Charlotte

    If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

    • krishnavzm's avatar
      krishnavzm
      Frequent Visitor

      Thanks for the help. I got an idea now. Will work on the actual model