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
andreazambon
Helper V
Helper V

Calculate the date with the max production for each machine

Hi there, 

 

I have the need above in the topi title, so for example, if this is my database:

MachineDateKg
M101/03/2022823
M115/05/2022186
M110/04/2022591
M225/06/2022173
M213/03/2022226
M215/07/2022949
M316/08/2022969
M317/10/2022761
M313/09/2022447

The result that i'm trying to reach is this:

MachineDateKg
M101/03/2022823
M215/07/2022949
M316/08/2022969

 

Actually, i've tried in two ways:

 

1) with a report filter, putting a "prime N" filter on date, order by Kg produced. But this doesn't work because it finds the day with the max unit produced for all the machines and then the report finds the production for that day for each machine.

 

2) with a DAX formula: 

 

CALCULATE(MAX(Table1[Date]),ALLEXCEPT(Table1,Table1[Kg]))

 

 

but simply that formula is not correct somewhere. 

 

Some suggestions? 🙂

Thanks.

2 ACCEPTED SOLUTIONS
BeaBF
Impactful Individual
Impactful Individual

@andreazambon Hi!

You have to calculate the measure:

Measure =
VAR MAXKG = CALCULATE(MAX('Table'[Kg]), ALLEXCEPT('Table','Table'[Machine]))
RETURN CALCULATE(MAX('Table'[Date]),'Table'[Kg] = MAXKG)
 
Then put this measure in a table visual with Machine and the MAX of Kg and you'll obtain your result.
 
Let me know,
BBF

View solution in original post

BeaBF
Impactful Individual
Impactful Individual

@andreazambon ok, allora questa la formula:

 

Measure 2 =
VAR MAXKG = CALCULATE(MAX('Table (2)'[kg versati stato AM]), ALLEXCEPT('Table (2)','Table (2)'[Centro di Lavoro]), FILTER('Table (2)', 'Table (2)'[Tipo] in {"0","1","4"}))
RETURN CALCULATE(MAX('Table (2)'[Data Produzione]),'Table (2)'[kg versati stato AM] = MAXKG )
 
in tabella metti i seguenti campi:
BeaBF_0-1660215892095.png

 

BBF

View solution in original post

18 REPLIES 18
andreazambon
Helper V
Helper V

Also, i found that 'kg buoni' is itself a formula... probably this is the issue.

@BeaBF 

 

can you use this as a sample?

Data ProduzioneOrdine ClienteCentro di LavoroCausa ScartoCodice ClienteCodice MaterialeStatoTipoTurnoOperatorekg buoni colm buoni colkg versati stato AM
########600017459002 2018515,19E+09M0 1234999  474
########600017149002 2018515,19E+09M0 1234999  420
########200197739002 2013715,14E+09M0 1234999  284
########600016899002 2015145,15E+09M0 1234999  470
########200211649002 2015145,15E+09M0 1234999  552
########200205249002 2006865,07E+09M0 1234999  346
########(vuoto)9001 (vuoto)50M0 1234999  1.871
########(vuoto)9001 (vuoto)50M0 1234999  546
########200216179001 2081805,82E+09M0 1234999  546
########200243209001 2016645,16E+09M0 1234999  775
########(vuoto)9001 (vuoto)50M0 1234999  748
########800027899001 1067115,67E+09M0 1234999  116
########800027909001 1067115,67E+09M0 1234999  126
########800027919001 1067115,67E+09M0 1234999  118
########200238739001 2019185,19E+09M0 1234999  655

 

 

formula for kg buoni:

 

kg buoni = calculate(sum(zbob_tot[kg versati stato AM]),filter(zbob_tot,zbob_tot[Tipo] IN {"0", "1", "4"}))
BeaBF
Impactful Individual
Impactful Individual

@andreazambon  the arranged formula:

Measure =
VAR MAXKG = CALCULATE(MAX('Table'[Kg]), ALLEXCEPT('Table','Table'[Machine]), FILTER('Table', 'Table'[Tipo] in {"0","1","4"}))
RETURN CALCULATE(MAX('Table'[Date]),'Table'[Kg] = MAXKG )
 
Kg is your field named kg versati stato AM.
Try,
BBF

Seems that is not working. 

Your measure give me different day for each machine, but it's not the date where i have the MAX production.

 

For example, with "Centro di Lavoro" = 2016 (named CAST 😎 the day with the max production is 08/03/2022, your formula gave me 21/03/2022.

 

I'm sorry but i cant show you the correct data about the kg produced

 

Including your measure in my report, I see this, with wrong numbers:

 

andreazambon_1-1660211620979.png

'Impianto' is given by  another table linked to zbob_tot via  "centro di lavoro". (Impianto is the name of centro di lavoro).

Consider that in a day I can produce from 10.000 to 40.000 kg

 

 

Now, that sum of kg seems to be the production of 6 months of work, if it can help.

 

BeaBF
Impactful Individual
Impactful Individual

@andreazambon italiano?

 

Ripartiamo sui dati reali, perchè abbiamo fatto un po' di confusione. Dato il seguente dataset:

Data ProduzioneOrdine ClienteCentro di LavoroCausa ScartoCodice ClienteCodice MaterialeStatoTipoTurnoOperatorekg buoni colm buoni colkg versati stato AM

giovedì 12 agosto 2021 60001745 9002   201851 5190000000 M 0   1234999     474
lunedì 12 settembre 2022 60001714 9002   201851 5190000000 M 0   1234999     420
venerdì 13 luglio 2018 20019773 9002   201371 5140000000 M 0   1234999     284
venerdì 13 luglio 2018 60001689 9002   201514 5150000000 M 0   1234999     470
venerdì 13 luglio 2018 20021164 9002   201514 5150000000 M 0   1234999     552
venerdì 13 luglio 2018 20020524 9002   200686 5070000000 M 0   1234999     346
lunedì 13 maggio 2019 (vuoto) 9001   (vuoto) 50 M 0   1234999     1871
lunedì 23 aprile 2018 (vuoto) 9001   (vuoto) 50 M 0   1234999     546
martedì 17 novembre 2020 20021617 9001   208180 5820000000 M 0   1234999     546
venerdì 13 luglio 2018 20024320 9001   201664 5160000000 M 0   1234999     775
venerdì 13 luglio 2018 (vuoto) 9001   (vuoto) 50 M 0   1234999     748
venerdì 13 luglio 2018 80002789 9001   106711 5670000000 M 0   1234999     116
lunedì 13 luglio 2020 80002790 9001   106711 5670000000 M 0   1234999     126
martedì 13 luglio 2021 80002791 9001   106711 5670000000 M 0   1234999     118
venerdì 13 luglio 2018 20023873 9001   201918 5190000000 M 0   1234999    

655

 

potresti dirmi qual è l'output desiderato?

 

BBF

Premesso che deve valere la formula della misura "kg buoni", dato quel dataset, il risultato desiderato è il seguente:

DataCdlKg
venerdì 13 luglio 20189002552
lunedì 13 maggio 201990011871

 

 

In pratica, per ogni macchina mi devi dire in quale data ho ottenuto la produzione più alta, e se voglio, anche quanto ho prodotto. 

 

BeaBF
Impactful Individual
Impactful Individual

@andreazambon ok, allora questa la formula:

 

Measure 2 =
VAR MAXKG = CALCULATE(MAX('Table (2)'[kg versati stato AM]), ALLEXCEPT('Table (2)','Table (2)'[Centro di Lavoro]), FILTER('Table (2)', 'Table (2)'[Tipo] in {"0","1","4"}))
RETURN CALCULATE(MAX('Table (2)'[Data Produzione]),'Table (2)'[kg versati stato AM] = MAXKG )
 
in tabella metti i seguenti campi:
BeaBF_0-1660215892095.png

 

BBF

stesso problema di prima. Sospetto che il problema sia nel RETURN: calcolare il MAX di kg versati stato AM, senza filtrarlo, potrebbe non corrispondere a max di kg_buoni

BeaBF
Impactful Individual
Impactful Individual

@andreazambon non capisco il problema, l'output è ciò che volevi. Qual è il problema?

 

 

nel mio dataset originale, purtroppo i dati non battono, nel senso che la tua formula mi da un risultato ma se "spulcio" i dati, trovo una tupla per lo stesso cdl con una produzione maggiore.

Tuttavia, se hai fatto dei test e la formula funziona, molto probabilmente è il dataset mio ad avere un filtraggio particolare, e li ci facciamo poco.

 

BeaBF
Impactful Individual
Impactful Individual

Riesci a condividere il pbix? così lavoro sul tuo stesso dataset

Vorrei, ma purtroppo contiene molti dati sensibili che per ragioni ovvie non posso condividere. 

Ritengo comunque la mia richiesta soddisfatta, tieni presente che sono nuovo in questa azienda e non conosco a menadito il dataset. Se i test hanno confermato la validità della cosa, direi che possiamo fermarci.

Ti ringrazio per avermi seguito 🙂

BeaBF
Impactful Individual
Impactful Individual

@andreazambon yes, can you paste the formula of kg buoni?

 

BBF

you have it below the table

Jihwan_Kim
Super User
Super User

Hi,

Please check the below picture and the attached pbix file.

It is for creating a measure.

 

Picture2.png

 

Date with Max KG measure: = 
VAR _maxkg =
    MAX ( Data[Kg] )
RETURN
    IF (
        HASONEVALUE ( Data[Machine] ),
        CALCULATE ( MAX ( Data[Date] ), Data[Kg] = _maxkg )
    )

If this post helps, then please consider accepting it as the solution to help other members find it faster, and give a big thumbs up.


Go to My LinkedIn Page


BeaBF
Impactful Individual
Impactful Individual

@andreazambon Hi!

You have to calculate the measure:

Measure =
VAR MAXKG = CALCULATE(MAX('Table'[Kg]), ALLEXCEPT('Table','Table'[Machine]))
RETURN CALCULATE(MAX('Table'[Date]),'Table'[Kg] = MAXKG)
 
Then put this measure in a table visual with Machine and the MAX of Kg and you'll obtain your result.
 
Let me know,
BBF

Hi, 

 

adapting my real table, i've got this:

 

Measure =
VAR MAXKG = CALCULATE(MAX(zbob_tot[kg buoni]), ALLEXCEPT(zbob_tot, zbob_tot[Centro di lavoro]))
RETURN CALCULATE(MAX(zbob_tot[Data Produzione]),zbob_tot[kg buoni] = MAXKG)
 
This give me the error "Column 'kg buoni' in table 'zbob_tot' cannot be found or may not be used in this expression.".
 
Does this formula need some format for the 'kg buoni' column? Actually is formatted as int number.
 

 

 

BeaBF
Impactful Individual
Impactful Individual

@andreazambon no, it is correct in number format. 

Can you paste a sample of real data?

 

Thx,

BBF

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