Skip to main content
cancel
Showing results for 
Search instead for 
Did you mean: 

Earn the coveted Fabric Analytics Engineer certification. 100% off your exam for a limited time only!

Reply
pawelj795
Post Prodigy
Post Prodigy

Quickly DAX measure fix - Filter

Hi,
I want to slightly modify my measure.
Currently, it looks like that: 


Aging =

VAR ItemID = SELECTEDVALUE(WH_Invent_Trans[ItemID])

RETURN
DATEDIFF(MAXX(
FILTER(ALL(WH_Invent_Trans); WH_Invent_Trans[ItemID] = ItemID);
WH_Invent_Trans[Date Physical]);
TODAY()-1;DAY)
 
But I want add to this measure 2 conditions.
Firstly, It must be only TransType = 0 or = 9 (transtype is column in table WH_Invent_Trans with values from 0 to 9)
Secondly, QTY<>BLANK (it also column in table WH_Invent_Trans)

I would appreciate any ideas 🙂
1 ACCEPTED SOLUTION

hej @pawelj795 

 

W pliku ktory wyslales nie bylo tego obiektu wiec musiale go wylachys z formuly.

 

Zalaczylem plik z formua.

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

 

View solution in original post

31 REPLIES 31
pawelj795
Post Prodigy
Post Prodigy

@Mariusz 

Jestes w stanie mi pomoc?

Hi @pawelj795 

 

Spoko, dodaj ponizsze jako dodatkowy argument w ostatnim CALCULATE.

DimDates[Date] <= DATE( 2019, 1, 1 )
 
Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

pawelj795
Post Prodigy
Post Prodigy

@Mariusz 

Formuła działa prawie prawidłowo.
Potrzebuje tylko zmienić by do zwracanej wartości (Inventory Value EUR) nie był brany filtr na Trans Type, tzn wartość powinna być wyliczana YTD ale dla każdego typu Trans Type.

Hej Pawel,

 

sprobuj tego,

M = 
VAR __tbl =
    FILTER(
        GROUPBY(
            CALCULATETABLE(
                WH_Invent_Trans,
                --KEEPFILTERS( WH_Invent_Trans[TransType] IN { 0, 9 } ),
                KEEPFILTERS( WH_Invent_Trans[QTY] <> BLANK() ),
                ALLEXCEPT( WH_Invent_Trans, WH_Invent_Trans[ItemID] )
            ),
            WH_Invent_Trans[ItemID],
            "@maxDate", MAXX( CURRENTGROUP(), WH_Invent_Trans[DatePhysical] )
        ),
        VAR __days = DATEDIFF( [@maxDate], TODAY() -1, DAY )
        RETURN __days > 0 && __days <= 276 --changed as 15 was out of range
    )
RETURN 
    CALCULATE(
        SUM( WH_Invent_Trans[Inventory Value EUR] ),
        TREATAS( __tbl, WH_Invent_Trans[ItemID], WH_Invent_Trans[DatePhysical] )
        --DATESYTD(DimDates[Date]);
    )

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

@Mariusz 

Chyba nie do końca dobrze wytłumaczyłem wszystko.

Chodzi o to, żeby do wiekowania, wybór indeksów był na podstawie trans type 0 i 9. -> czyli w _tbl filtr musi pozostać.

Natomiast do wyliczenia wartości wybranych indeksów były brane wszystkie transakcje (bez filtra na trans type). -> jak wyłączyć filtr na trans type w Treatas?




Hej @pawelj795 

 

Spobuj, tego

 

M = 
VAR __tbl =
    FILTER(
        GROUPBY(
            CALCULATETABLE(
                WH_Invent_Trans,
                KEEPFILTERS( WH_Invent_Trans[TransType] IN { 0, 9 } ),
                KEEPFILTERS( WH_Invent_Trans[QTY] <> BLANK() ),
                ALLEXCEPT( WH_Invent_Trans, WH_Invent_Trans[ItemID] )
            ),
            WH_Invent_Trans[ItemID],
            "@maxDate", MAXX( CURRENTGROUP(), WH_Invent_Trans[DatePhysical] )
        ),
        VAR __days = DATEDIFF( [@maxDate], TODAY() -1, DAY )
        RETURN __days > 0 && __days <= 276 --changed as 15 was out of range
    )
RETURN 
    CALCULATE(
        SUM( WH_Invent_Trans[Inventory Value EUR] ),
        TREATAS( 
            SUMMARIZE( __tbl, WH_Invent_Trans[ItemID] ), WH_Invent_Trans[ItemID] 
        )
        --DATESYTD(DimDates[Date]);
    )

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

@Mariusz 

Dostaje błąd: "The end of the input was reached"

Dlaczego YTD wylaczyles z formuly?

hej @pawelj795 

 

W pliku ktory wyslales nie bylo tego obiektu wiec musiale go wylachys z formuly.

 

Zalaczylem plik z formua.

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

 

@Mariusz 
Cześć,
Musze niestety odkopać temat, bo pojawił się problem od startu nowego roku.
Formuła nierozpoznaje dni z poprzedniego roku, jako, że w sumie użyte było DATESYTD.
Aktualnie pokazuje tylko wiekowanie na 0-15 dni i to też niepoprawnie, bo pokazuje wartosc - 14 tysięcy

 

 

image.png
Byłbym bardzo wdzięczny, jak mogłbyś mi z tym pomóc 🙂

Hi @pawelj795 

 

You can add an extra variable __date and later use it as the third argument of CALCULATE, there are three extra lines followed by "--new" in the code, this is to replace DATESYTD.
Please see the below for reference.

 

M = 
VAR __tbl =
    FILTER(
        GROUPBY(
            CALCULATETABLE(
                WH_Invent_Trans,
                KEEPFILTERS( WH_Invent_Trans[TransType] IN { 0, 9 } ),
                KEEPFILTERS( WH_Invent_Trans[QTY] <> BLANK() ),
                ALLEXCEPT( WH_Invent_Trans, WH_Invent_Trans[ItemID] )
            ),
            WH_Invent_Trans[ItemID],
            "@maxDate", MAXX( CURRENTGROUP(), WH_Invent_Trans[DatePhysical] )
        ),
        VAR __days = DATEDIFF( [@maxDate], TODAY() -1, DAY )
        RETURN __days > 0 && __days <= 276 --changed as 15 was out of range
    )
VAR __date = MAX( DimDates[Date] ) -- new
RETURN 
    CALCULATE(
        SUM( WH_Invent_Trans[Inventory Value EUR] ),
        TREATAS( 
            SUMMARIZE( __tbl, WH_Invent_Trans[ItemID] ), WH_Invent_Trans[ItemID] 
        ),
        DimDates[Date] <= __date, -- new
        ALL( DimDates ) -- new
    )

 

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

@Mariusz 
Jest coś nie tak.
Wydaje mi się, że to przez to, że obecna miara bierze wartości "od poczatku świata".

Można ustawić, żeby wartości były brane od 01.01.2019?

Bo z tego co rozumiem na końcu miary RETURN funkcja ALL czyści wszelkie filtry na daty?

Dokładnie o to mi chodziło 😉
Bardzo ci dziękuje za pomoc i wesołych świąt !

@pawelj795 

 

spoko, wesolych swiat!

@Mariusz 
Witam w nowym roku 🙂

Potrzebuje jednej drobnej rzeczy do stworzonej przez ciebie formuly.

Mianowicie chciałbym stworzyć tabelę, w której oprócz ItemID i wartości będzie data ostatniej transakcji na danym itemie.
Oczywiście wszelkie filtry, które były używane do wyliczenia wartości zostaną.

Próbowałem sam stworzyć tą miarę w banalny sposób, tzn. wycięcia z twojej formuły z wartością, fragmentu z datą, ale nic mi to nie przyniosło.

Hi @pawelj795 

 

sprobuj tego

date = 
VAR __dates = 
    GROUPBY(
        CALCULATETABLE(
            WH_Invent_Trans,
            KEEPFILTERS( WH_Invent_Trans[TransType] IN { 0, 9 } ),
            KEEPFILTERS( WH_Invent_Trans[QTY] <> BLANK() ),
            ALLEXCEPT( WH_Invent_Trans, WH_Invent_Trans[ItemID] )
        ),
        WH_Invent_Trans[ItemID],
        "@maxDate", MAXX( CURRENTGROUP(), WH_Invent_Trans[DatePhysical] )
    )
RETURN MAXX( __dates, [@maxDate] )

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

@Mariusz 
Can you help me?
With your new measures my total are twice as big than whole inventory value(2,16 m vs. 1m)image.png

 

Mariusz
Community Champion
Community Champion

Hi @pawelj795 

 

Try something like  this.

Aging =
VAR ItemID = SELECTEDVALUE( WH_Invent_Trans[ItemID] )
RETURN
DATEDIFF(
    MAXX(
        FILTER(
            ALL( WH_Invent_Trans ); 
            WH_Invent_Trans[ItemID] = ItemID
            && WH_Invent_Trans[TransType] IN { 0, 9 }
            && WH_Invent_Trans[QTY] <> BLANK
        );
        WH_Invent_Trans[Date Physical]
    );
    TODAY()-1;
    DAY
)
Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

 

That works, thanks 😉

Now, I want to develop this measure.

Groups = 
VAR ItemID = SELECTEDVALUE(WH_Invent_Trans[ItemID])

VAR DateDifference = 
DATEDIFF(
    MAXX(
        FILTER(WH_Invent_Trans;
        WH_Invent_Trans[ItemID]=ItemID
        && WH_Invent_Trans[TransType] IN {0;9}
        && WH_Invent_Trans[QTY] <> BLANK()
        );
        WH_Invent_Trans[Date Physical]);
        TODAY()-1;
        DAY)

RETURN
CALCULATE(
    SUM(
        WH_Invent_Trans[Inventory Value EUR]);
        DATESYTD(DimDates[Date]);
        DateDifference > 0 && DateDifference<= 15)



But it doesn't work.

It shows:
the true/false expression does not specify a column. Each true/false expressions used as table filter expression must refer to exactly one column

@Mariusz 
Niestety to nie pomoglo, nadal wartości są z kosmosu.

Czy możesz mi wytłumaczyć co w formule zmieniło dodanie ALL do ostatniego CALCULATE?
Moze w ten sposob bede w stanie zidentyfikowac problem.

Hi @pawelj795 

 

ALL( dimDate ) usunelow filtry z dimDate, to umozliwilo ( Running Total ) jak z DATESYTD tylko od pierwszej date w tabeli.

 

Best Regards,
Mariusz

If this post helps, then please consider Accepting it as the solution.

Please feel free to connect with me.
LinkedIn

 

Helpful resources

Announcements
April AMA free

Microsoft Fabric AMA Livestream

Join us Tuesday, April 09, 9:00 – 10:00 AM PST for a live, expert-led Q&A session on all things Microsoft Fabric!

March Fabric Community Update

Fabric Community Update - March 2024

Find out what's new and trending in the Fabric Community.

Top Solution Authors