Forum Discussion

Marc76's avatar
Marc76
Frequent Visitor
7 years ago
Solved

Context problem. ALL, ALLSELECTED, ...

Hi,    I need help with context,    I 've this schema The Invoice's Total is saved in InvoicePayablePart (summatory) because InvoicePayablePart has the parts in wich the Invoice is partiti...
  • Anonymous's avatar
    Anonymous
    7 years ago

    Well, I'm not English, either.

     

    First of all, you should use Power Query to get your data into good shape. It's easy to use PQ and it's a very powerful data mash-up engine.

     

    Secondly, you should read on DAX because you're completely in the dark on how it really works. If you do invest some time into it, you'll save yourself hours of frustration. I promise.

     

    -- First of all, your Calendar must be marked as a Date Table
    -- in the model for this to work correctly. Secondly, you
    -- don't probably know this but it's of crucial importance
    -- that when you filter a measure by a whole table, you are in fact
    -- filtering by THE EXPANDED TABLE version of the table in question.
    -- You should never filter by a whole table unless you're asking for
    -- trouble or you know precisely why you do it. When you filter,
    -- please filter by individual columns only. You should also know
    -- that RELATED should only be used when there is a row context
    -- present, so it can be used in iterators only. CALCULATE
    -- is not an iterator.
    
    [Payable To Date] =
    var __maxDate = MAX( 'Calendar'[Date] )
    var _payableToDate =
    	CALCULATE (
    	    SUM ( InvoicePayablePart[Debt] ),
    	    'Calendar'[Date] <= __maxDate
    	)
    return
    	__payableToDate
    	
    [Paid To Date] =
    var __maxDate = MAX( 'Calendar'[Date] )
    var __paidToDate =
        CALCULATE (
            SUM ( InvoicePayedPart[Payed] ), -- change to Paid
            ALL( 'Calendar' ),
            InvoicePayedPart[PaymentDate] <= __maxDate
        )
    return
    	__paidToDate
    	
    
    [Outstanding Debt] = [Payable To Date] - [Paid To Date]

    Best

    Darek