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

Grow your Fabric skills and prepare for the DP-600 certification exam by completing the latest Microsoft Fabric challenge.

Reply
cprpontes
Regular Visitor

Automate operator for each change in root table

I have two separate tables, where 1 has the failures and the times that happened each one of them, the other table is the names of the operators that test a product where failures happen for each operator.
I need to automate where if I change the operator in the operator source table. the most I could be to do like this, but if I change the operator, I have to change the code manually.

I appreciate all the support needed and I don't know if the understanding was explained.

tables of operators:

cprpontes_0-1630446945380.png

table of failures:

cprpontes_1-1630447064167.png

my code:

REV OPER = SWitch(True(),
'FAILURES STATION'[HR I/F] > TIME(06,55,0) && 'FAILURES STATION'[HR I/F] < TIME(09,10,0) && 'FAILURES STATION'[ESTAÇÃO]="FAT", "MOTA",
'FAILURES STATION'[HR I/F] > TIME(14,35,0) && 'FAILURES STATION'[HR I/F] < TIME(16,57,0) && 'FAILURES STATION'[ESTAÇÃO]="CS", "MOTA",
'FAILURES STATION'[HR I/F] > TIME(09,10,0) && 'FAILURES STATION'[HR I/F] < TIME(11,20,0) && 'FAILURES STATION'[ESTAÇÃO]="FAT", "SERGIO",
'FAILURES STATION'[HR I/F] > TIME(06,55,0) && 'FAILURES STATION'[HR I/F] < TIME(09,10,0) && 'FAILURES STATION'[ESTAÇÃO]="CS", "SOCORRO",
'FAILURES STATION'[HR I/F] > TIME(14,35,0) && 'FAILURES STATION'[HR I/F] < TIME(16,59,0) && 'FAILURES STATION'[ESTAÇÃO]="FAT", "SOCORRO",
'FAILURES STATION'[HR I/F] > TIME(12,15,0) && 'FAILURES STATION'[HR I/F] < TIME(14,30,0) && 'FAILURES STATION'[ESTAÇÃO]="FAT", "WILLAMES",
'FAILURES STATION'[HR I/F] > TIME(09,15,0) && 'FAILURES STATION'[HR I/F] < TIME(11,20,0) && 'FAILURES STATION'[ESTAÇÃO]="CS", "WILLAMES",
'FAILURES STATION'[HR I/F] > TIME(12,15,0) && 'FAILURES STATION'[HR I/F] < TIME(14,30,0) && 'FAILURES STATION'[ESTAÇÃO]="CS", "JUCELINO")
 
I would like it to be like this, however automatic when in the source table is changed, operator.
 
1 ACCEPTED SOLUTION

Hi @cprpontes ,

 

Please try the following to see if the problem above still occurs.

Calculate the maximum time and minimum time.

 

Max Time =
CALCULATE (
    MAX ( 'operators'[HR I/F] ),
    FILTER (
        'operators',
        'operators'[OPERADOR] = EARLIER ( 'operators'[OPERADOR] )
            && 'operators'[ESTAÇÃO] = EARLIER ( 'operators'[ESTAÇÃO] )
    )
)

 

Min Time =
CALCULATE (
    MIN ( 'operators'[HR I/F] ),
    FILTER (
        'operators',
        'operators'[OPERADOR] = EARLIER ( 'operators'[OPERADOR] )
            && 'operators'[ESTAÇÃO] = EARLIER ( 'operators'[ESTAÇÃO] )
    )
)

 

Then:

REV OPER =
CALCULATE (
    MAX ( 'operators'[OPERADOR] ),
    FILTER (
        'operators',
        'operators'[Min Time] < EARLIER ( 'Failures'[HR I/F] )
            && 'operators'[Max Time] > EARLIER ( 'Failures'[HR I/F] )
            && 'operators'[ESTAÇÃO] = EARLIER ( 'Failures'[ESTAÇÃO] )
    )
)

 

A sample PBIX. for your reference is attached.

Hope it helps,


Community Support Team _ Caitlyn Yan


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

 

View solution in original post

4 REPLIES 4
v-xiaoyan-msft
Community Support
Community Support

Hi @cprpontes ,

 

Please try this in query editor:

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("jdfBasJQEIXhVylZCya3ub33ZhfElhRtirG4EN//NWqLaDwzkzmbkMUPIYdvM+dztR+PfbWq8rp5W4c6NNf39/54faaurl/6fXVZLUSla+7RtD18DKORBSZrmll3Gna7fr+d9DL8ld9EGbrXeziNm/Fw0L8dupbq2i7G5W4zwXoL2Xw/4zdunTvMf/e04OfPZrsbvtQPPw24FM73UxjcmtZt5rs9msSYS5w5kenmEm0OS9tcIs2JzjCXSHOJM5dIc9i5w3jmEmsuEeaw0cwlwlxmzGXOnMh0c5k2h6VtLpPmRGeYy6S5zJnLpDns3GE8c5k1lwlz2GjmMmGuMOYKZ05kurlCm8PSNldIc6IzzBXSXOHMFdIcdu4wnrnCmiuEOWw0c8U3F1rCHEaGOZmp5jCzzYnSNIelZU52ujnsLHOPbtEcZKY50bnDOOYwNM1BqJoTjWIOGt1cZMxFzpzIdHORNoelbS6S5kRnmIukuciZi6Q57NxhPHORNRcJc9ho5iJhjrlbMbLMcXcrZgvm6LsVS9McebdiZ5rj7tZA3q2ic4fxzLF3ayDuVtFo5oy79fIL", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [OPERADOR = _t, DATA = _t, ESTAÇÃO = _t, #"HR I/F" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"OPERADOR", type text}, {"DATA", type date}, {"ESTAÇÃO", type text}, {"HR I/F", type time}}),
    #"Grouped Rows" = Table.Group(#"Changed Type", {"OPERADOR", "ESTAÇÃO"}, {{"MaxTime", each List.Max([#"HR I/F"]), type nullable time}, {"MinTime", each List.Min([#"HR I/F"]), type nullable time}, {"Table", each _, type table [OPERADOR=nullable text, DATA=nullable date, ESTAÇÃO=nullable text, #"HR I/F"=nullable time]}}),
    #"Expanded Table" = Table.ExpandTableColumn(#"Grouped Rows", "Table", {"DATA", "HR I/F"}, {"Table.DATA", "Table.HR I/F"})
in
    #"Expanded Table"

 

(currentESTACAO, currentHR) => 
let 
    source = Table.SelectRows(#"F277 REVEZAMENTO TESTE", each [ESTAÇÃO] = currentESTACAO and [MinTime] < currentHR and [MaxTime] > currentHR){0}[OPERADOR]
in 
    source

 

let
    Source = Table.FromRows(Json.Document(Binary.Decompress(Binary.FromText("pVvbbhtHEv0Vws8B0vfLvMmUEhkbawVJ3iwQBITWoR0itrRLS5tFvn67uoecGk5Vd8tGAj0E4UHd61RVzy+/vPrnD8r7oKRWSkghjJOvvnu1vk1/fvh5dX65vl7dbP/zvP3ylP5L+F7675VQ8L+4warByNXZ21e/fodhdIKRKoQqjEMwftB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ZtF8SYGBQDfGRtFWx8jJPiYvaLiBS05vDZhegQykqHwfmao2vfdvA72Cisbxo5sWdcZAiryIlPfmtroJ8wjFwwMl2l+y9egK+0vTm+FCwNFHSY2mbPLXClzay9DqFkg1Q3fl8tpu+syx8b474yy76SGkwxTSVFOOMxj2HiFE32tWk+v8InwOY2l4QX6l6spxBGjLDX8hiSx10z2McLo+XCArWwWPLAHm1/8D", BinaryEncoding.Base64), Compression.Deflate)), let _t = ((type nullable text) meta [Serialized.Text = true]) in type table [TRACEABILITY = _t, ESTAÇÃO = _t, #"DESCRIÇÃO FALHA" = _t, Data = _t, #"HR I/F" = _t]),
    #"Changed Type" = Table.TransformColumnTypes(Source,{{"Data", type date}, {"HR I/F", type time}}),
    #"Added Custom" = Table.AddColumn(#"Changed Type", "Custom", each try test([ESTAÇÃO],[#"HR I/F"]) otherwise "")
in
    #"Added Custom"


A sample PBIX. for your reference is attached.

 

Hope it helps,


Community Support Team _ Caitlyn Yan


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

Hi 

@v-xiaoyan-msft 

I really appreciate your support and I was able to do almost everything with my datasheet, it was very good I really appreciate your help, but if I can check one more problem.
after many attempts, I managed to do it through your advice, to stay automatically when an operator is changed as shown in the table below, look in the table that I changed only on the date 26.08.2021. I don't understand why the operator "charles" appears on other dates, I've tried to change some things in the code but without success.

There was a change of operator (CHARLES)

cprpontes_0-1630716420624.png

In the BI power table "FAILURES STATION" 

however, I only changed the operator on the date 26/08.2021, and in the table of defects the operator Charles appears on other dates as shown in the table below, I just wanted it to show the operator only on the date it was placed in the table, that is it should not appear on other dates.

 

cprpontes_0-1630760867319.png

 

 

 

Please, when you had some time for me, I would like your help to solve this problem.
thank you very much for the support.

follows the PBIX, with the changes I made based on its code:

 

 

https://drive.google.com/file/d/1pHw0YM2GYv-KjEdP0fH1e93h_Z99-RAk/view?usp=sharing

 

 

 

 

 

Hi @cprpontes ,

 

Please try the following to see if the problem above still occurs.

Calculate the maximum time and minimum time.

 

Max Time =
CALCULATE (
    MAX ( 'operators'[HR I/F] ),
    FILTER (
        'operators',
        'operators'[OPERADOR] = EARLIER ( 'operators'[OPERADOR] )
            && 'operators'[ESTAÇÃO] = EARLIER ( 'operators'[ESTAÇÃO] )
    )
)

 

Min Time =
CALCULATE (
    MIN ( 'operators'[HR I/F] ),
    FILTER (
        'operators',
        'operators'[OPERADOR] = EARLIER ( 'operators'[OPERADOR] )
            && 'operators'[ESTAÇÃO] = EARLIER ( 'operators'[ESTAÇÃO] )
    )
)

 

Then:

REV OPER =
CALCULATE (
    MAX ( 'operators'[OPERADOR] ),
    FILTER (
        'operators',
        'operators'[Min Time] < EARLIER ( 'Failures'[HR I/F] )
            && 'operators'[Max Time] > EARLIER ( 'Failures'[HR I/F] )
            && 'operators'[ESTAÇÃO] = EARLIER ( 'Failures'[ESTAÇÃO] )
    )
)

 

A sample PBIX. for your reference is attached.

Hope it helps,


Community Support Team _ Caitlyn Yan


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

 

thank you very much for the support, now it worked as expected, through your help the code was great.
I just added one more condition to get the date linked to the operator. thank you!

 

cprpontes_0-1631197006084.png

 

Helpful resources

Announcements
RTI Forums Carousel3

New forum boards available in Real-Time Intelligence.

Ask questions in Eventhouse and KQL, Eventstream, and Reflex.

MayPowerBICarousel1

Power BI Monthly Update - May 2024

Check out the May 2024 Power BI update to learn about new features.