Forum Discussion

farooqk's avatar
farooqk
Regular Visitor
3 years ago
Solved

Many to one relationship duplicate value

I have this data:

DateMasterCategorySubCategoryAmount
8-August-2022FoodGrocery200
8-August-2022FoodGrocery31
8-August-2022FoodRestaurant40
8-August-2022ShoppingElectronics30
9-August-2022FoodGrocery10
10-August-2022ShoppingElectronics5
11-August-2022FoodRestaurant10
12-August-2022ShoppingGrocery10

 

My goal is to generate

DateMasterCategorySubCategoryTotal Amount
2022-08-08 00:00:00FoodGrocery231
2022-08-08 00:00:00FoodRestaurant40
2022-08-08 00:00:00ShoppingElectronics30
2022-08-08 00:00:00ShoppingGrocery0
2022-08-09 00:00:00FoodGrocery10
2022-08-09 00:00:00FoodRestaurant0
2022-08-09 00:00:00ShoppingElectronics0
2022-08-09 00:00:00ShoppingGrocery0
2022-08-10 00:00:00FoodGrocery0
2022-08-10 00:00:00FoodRestaurant0
2022-08-10 00:00:00ShoppingElectronics5
2022-08-10 00:00:00ShoppingGrocery0
2022-08-11 00:00:00FoodGrocery0
2022-08-11 00:00:00FoodRestaurant10
2022-08-11 00:00:00ShoppingElectronics0
2022-08-11 00:00:00ShoppingGrocery0
2022-08-12 00:00:00FoodGrocery0
2022-08-12 00:00:00FoodRestaurant0
2022-08-12 00:00:00ShoppingElectronics0
2022-08-12 00:00:00ShoppingGrocery10

 

I have almost hit the goal but now I am running into this error within my linked solution:

 


 Most likely being caused by last line of the data.

 

I hope someone can provide a solution here.

  • Hi farooqk 

    Please remove the relationship first, then use this DAX expression to create a new table:

    New Table = 
    VAR _Date =
        VALUES ( Data[Date] )
    VAR _Cat =
        SUMMARIZE ( Data, Data[MasterCategory], Data[SubCategory] )
    RETURN
        ADDCOLUMNS (
            CROSSJOIN ( _Date, _Cat ),
            "Amount", CALCULATE ( SUM ( Data[Amount] ), KEEPFILTERS ( Data[Date] ) ) + 0
        )
    

     

    The output:

     

     

     

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

    Appreciate your Kudos!! 

    LinkedIn | Twitter | Blog | YouTube 

2 Replies

  • Hi farooqk 

    Please remove the relationship first, then use this DAX expression to create a new table:

    New Table = 
    VAR _Date =
        VALUES ( Data[Date] )
    VAR _Cat =
        SUMMARIZE ( Data, Data[MasterCategory], Data[SubCategory] )
    RETURN
        ADDCOLUMNS (
            CROSSJOIN ( _Date, _Cat ),
            "Amount", CALCULATE ( SUM ( Data[Amount] ), KEEPFILTERS ( Data[Date] ) ) + 0
        )
    

     

    The output:

     

     

     

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

    Appreciate your Kudos!! 

    LinkedIn | Twitter | Blog | YouTube