Forum Discussion

russds's avatar
russds
Frequent Visitor
7 years ago
Solved

Calculate using OR from Dimensions

I have a fairly simple model with 1 Fact table and 2 Dimensions.  Fact Table Sales:        SalesID, ProductID, StoreID ProductDim        ProductID, ProductName StoreDim        StoreID, StoreNam...
  • MattAllington's avatar
    MattAllington
    7 years ago

    Sorry, I missunderstood. You can’t do what you want if you have 2 active relationships. Relationships from 2 dim tables are logical AND. So either remove the relationships or make them inactive. Then write something like

     

    measure =
    VAR prod =
        MAX ( prod[id] )
    VAR Store =
        MAX ( store[ID] )
    VAR prodsales =
        FILTER ( sales, sales[prod id] = prod )
    VAR Storesales =
        FILTER ( sales, sales[store id] = store )
    VAR allsales =
        UNION ( prodsales, storesales ) // includes 2 copies of rows that are both 
    VAR alldistinctsales =
        DISTINCT ( allsales ) // removes double count of rows that are both
    RETURN
        CALCULATE ( [total sales], Alldistinctsales)

    I think this will work. I haven’t tested it.