Hi guys
I am working on a pbix to analyze repair work in a car workshop. A Doc (invoice or credit note) can consist of multiple repairs, so I need counts for Repairs and docs.
Repair count is basically the number of repair lines on the invoice and in terms of DAX fairly straight forward to work through (albeit with some hefty power query first so as not sum invalid lines).
However Doc count is proving a little elusive. see below screen shot:
The highlighted rows are showing correctly; ie Repair count for each line and only 1 doc
This was difficult in itself with the standard running total patterns based around EARLIER either too slow or just not working and throwing errors. I overcame this by identifying the largest LastLogMagic (unique identifier for each row), then checked this against the current row. If matched then 1 otherwise zero. However I cannot get the measure to provide totals.
I am working with 2 measures during dev, just to keep things simple; one for the line calc then another measure to do the totalling which is applied to the visual. Line Amount is DocCountPrep and totals is DocCount. The Measure DocCount however is not providing totals as you can see above.See DAX below. I applied the same principles for RepairCount and all is fine - standard DAX pattern with SUMX(Summarize…),
So now I’m totally befuddled and not sure where to go next. It must be the MaxLog variable that is causing the problem as the only thing that is different between RepairCount and DocCount.
Help greatly appreciated
Pete
DocCountPrep =
VAR ServiceDoc = LOOKUPVALUE(
DOCStats[MainCount],
DOCStats[InvoiceNumber],
max( SO_Fact[InvoiceNumber] ),
DOCStats[MainType],
max( RepairCatgories[RepCat Desc] )
)
VAR MaxLog = CALCULATE(
max( SO_Fact[LastLogMagic] ),
Filter(
ALLSELECTED( SO_Fact ),
SO_Fact[InvoiceNumber] = max( SO_Fact[InvoiceNumber] )
)
)
VAR DocCount = Switch(
TRUE(),
Max( RepairCatgories[RepCat Desc] ) = "Service AND MOT", if(
max( SO_Fact[Category] ) = "Labour", ServiceDoc,
Blank()
),
Max( RepairCatgories[RepCat Desc] ) = "Service", if(
max( SO_Fact[Category] ) = "Labour", ServiceDoc,
Blank()
),
Max( RepairCatgories[RepCat Desc] ) = "MOT", if(
max( SO_Fact[Category] ) = "Labour", ServiceDoc,
Blank()
),
Max( RepairCatgories[RepCat Desc] ) = "Warranty", if(
max( SO_Fact[Category] ) = "Labour", ServiceDoc,
Blank()
),
Max( RepairCatgories[RepCat Desc] ) = "Internal - New", if(
max( SO_Fact[Category] ) = "Labour", ServiceDoc,
Blank()
),
Max( RepairCatgories[RepCat Desc] ) = "Internal - Used", if(
max( SO_Fact[Category] ) = "Labour", ServiceDoc,
Blank()
),
Max( RepairCatgories[RepCat Desc] ) = "Internal - Other", if(
max( SO_Fact[Category] ) = "Labour", ServiceDoc,
Blank()
),
//Max( RepairCatgories[RepCat Desc] ) = "Upsell" , LOOKUPVALUE( DOCStats[UpSellJob] , DOCStats[InvoiceNumber] , max( SO_Fact[InvoiceNumber] ) ) , // Max( RepairCatgories[RepCat Desc] ) = "Tyres" , LOOKUPVALUE( DOCStats[TyreJob] , DOCStats[InvoiceNumber] , max( SO_Fact[InvoiceNumber] ) ) , //Max( RepairCatgories[RepCat Desc] ) = "Coll AND Del" , LOOKUPVALUE( DOCStats[CollDelJob] , DOCStats[InvoiceNumber] , max( SO_Fact[InvoiceNumber] ) ) , // Max( RepairCatgories[RepCat Desc] ) = "Courtesy Car" , LOOKUPVALUE( DOCStats[CourtesyJob] , DOCStats[InvoiceNumber] , max( SO_Fact[InvoiceNumber] ) ) , // Max( RepairCatgories[RepCat Desc] ) = "Bodyshop Labour" , LOOKUPVALUE( DOCStats[BodyJob] , DOCStats[InvoiceNumber] , max( SO_Fact[InvoiceNumber] ) ) , // Max( RepairCatgories[RepCat Desc] ) = "Smart Repair" , LOOKUPVALUE( DOCStats[SmartDoc] , DOCStats[InvoiceNumber] , max( SO_Fact[InvoiceNumber] ) ) , // Max( RepairCatgories[RepCat Desc] ) = "Bodyshop Paint" , LOOKUPVALUE( DOCStats[PaintDoc] , DOCStats[InvoiceNumber] , max( SO_Fact[InvoiceNumber] ) ) , // Max( RepairCatgories[RepCat Desc] ) = "Other Labour" , LOOKUPVALUE( DOCStats[OtherJob] , DOCStats[InvoiceNumber] , max( SO_Fact[InvoiceNumber] ) ) , BLank() )
Return docCount * if(
sum( SO_Fact[Gross Sales] ) = 0,
0,
1
) * if(
max( SO_Fact[LastLogMagic] ) = MaxLog,
1,
0
)
And the Doc count measure:
DocCount =
VAR MaxLog = CALCULATE(
max( SO_Fact[LastLogMagic] ),
Filter(
ALLSELECTED( SO_Fact ),
SO_Fact[InvoiceNumber] = max( SO_Fact[InvoiceNumber] )
)
)
VAR test = SUMX(
SUMMARIZE(
SO_Fact,
RepairCatgories[RepCat Desc],
SO_Fact[Menu],
SO_Fact[Category],
SO_Fact[InvoiceNumber],
SO_Fact[ProductCode],
SO_Fact[LastLogMagic]
),
[DocCountPrep] * if(
max( SO_Fact[LastLogMagic] ) = MaxLog,
1,
0
)
) Return Test