DAX Max Month Measure

andrewr1

New Member
Joined
Dec 19, 2012
Messages
6

I am new to this DAX language and I am sure the solution isa very simple one, but I would appreciate some help.<o:p></o:p>

<o:p> </o:p>

I have created two measures. <o:p></o:p>

MAX MONTH=MONTH(MAX('MONTHLYSALES 002'[Date]))
2016 ADJ NET SALES-YTD= CALCULATE(SUM([ADJUSTED NET SALES]), 'MONTHLYSALES002'[CAL_YEAR]=2016,'MONTHLYSALES 002'[PERIOD]<=11)<o:p></o:p>


Which gives me the desired results in a Pivot table<o:p></o:p>

[TABLE="width: 582"]
<colgroup><col width="268" style="width: 201pt; mso-width-source: userset; mso-width-alt: 9801;"> <col width="103" style="width: 77pt; mso-width-source: userset; mso-width-alt: 3766;" span="4"> <col width="97" style="width: 73pt; mso-width-source: userset; mso-width-alt: 3547;"> <tbody>[TR]
[TD="class: xl68, width: 268"][/TD]
[TD="class: xl69, width: 103"]2016 ADJ NET SALES-TOTAL[/TD]
[TD="class: xl69, width: 103"]2016 ADJ NET SALES-YTD[/TD]
[TD="class: xl69, width: 103"]2017 ADJ NET SALES- YTD[/TD]
[TD="class: xl70, width: 103"]YTD % CHNG[/TD]
[TD="width: 97"]MAX MONTH[/TD]
[/TR]
[TR]
[TD="class: xl71"]FLEA & TICK[/TD]
[TD="class: xl65, align: right"]$34,273,033[/TD]
[TD="class: xl65, align: right"]$32,747,351[/TD]
[TD="class: xl67, align: right"]$34,925,113[/TD]
[TD="class: xl66, align: right"]6.7 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: xl71"]HEALTH AND BEAUTY CARE[/TD]
[TD="class: xl65, align: right"]$7,262,615[/TD]
[TD="class: xl65, align: right"]$6,407,594[/TD]
[TD="class: xl67, align: right"]$8,012,576[/TD]
[TD="class: xl66, align: right"]25.0 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: xl71"]FORMULATED TREATS[/TD]
[TD="class: xl65, align: right"]$6,379,316[/TD]
[TD="class: xl65, align: right"]$6,071,751[/TD]
[TD="class: xl67, align: right"]$5,327,003[/TD]
[TD="class: xl66, align: right"]-12.3 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: xl71"]DENTAL[/TD]
[TD="class: xl65, align: right"]$1,103,680[/TD]
[TD="class: xl65, align: right"]$1,017,407[/TD]
[TD="class: xl67, align: right"]$1,022,124[/TD]
[TD="class: xl66, align: right"]0.5 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: xl71"]ACCESSORIES AND TOYS[/TD]
[TD="class: xl65, align: right"]$229,835[/TD]
[TD="class: xl65, align: right"]$211,170[/TD]
[TD="class: xl67, align: right"]$195,077[/TD]
[TD="class: xl66, align: right"]-7.6 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: xl71"]NATURAL TREATS[/TD]
[TD="class: xl65, align: right"]$33,044[/TD]
[TD="class: xl65, align: right"]$33,044[/TD]
[TD="class: xl67, align: right"]$26,584[/TD]
[TD="class: xl66, align: right"]-19.5 %[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD="class: xl71"]WASTE MANAGEMENT & HOUSEBREAK[/TD]
[TD="class: xl65, align: right"]$31,189[/TD]
[TD="class: xl65, align: right"]$28,108[/TD]
[TD="class: xl67, align: right"]$11,783[/TD]
[TD="class: xl66, align: right"]-58.1 %[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD="class: xl71"]RAWHIDE[/TD]
[TD="class: xl65, align: right"]$31,445[/TD]
[TD="class: xl65, align: right"]$31,445[/TD]
[TD="class: xl67, align: right"]$4,574[/TD]
[TD="class: xl66, align: right"]-85.5 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: xl71"]Grand Total[/TD]
[TD="class: xl65, align: right"]$49,344,155[/TD]
[TD="class: xl65, align: right"]$46,547,870[/TD]
[TD="class: xl67, align: right"]$49,524,835[/TD]
[TD="class: xl66, align: right"]6.4 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
</tbody>[/TABLE]
<v:shapetype id="_x0000_t75" stroked="f" filled="f" path="m@4@5l@4@11@9@11@9@5xe" o:preferrelative="t" o:spt="75" coordsize="21600,21600"> <v:stroke joinstyle="miter"> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"> <v:f eqn="sum @0 1 0"> <v:f eqn="sum 0 0 @1"> <v:f eqn="prod @2 1 2"> <v:f eqn="prod @3 21600 pixelWidth"> <v:f eqn="prod @3 21600 pixelHeight"> <v:f eqn="sum @0 0 1"> <v:f eqn="prod @6 1 2"> <v:f eqn="prod @7 21600 pixelWidth"> <v:f eqn="sum @8 21600 0"> <v:f eqn="prod @7 21600 pixelHeight"> <v:f eqn="sum @10 21600 0"> </v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas> <v:path o:connecttype="rect" gradientshapeok="t" o:extrusionok="f"> <o:lock aspectratio="t" v:ext="edit"></o:lock></v:path></v:stroke></v:shapetype><v:shape id="Picture_x0020_3" style="width: 468pt; height: 132.75pt; visibility: visible; mso-wrap-style: square;" type="#_x0000_t75" o:spid="_x0000_i1026"> <v:imagedata o:title="" src="file:///C:/Users/arundell/AppData/Local/Temp/msohtmlclip1/01/clip_image001.emz"></v:imagedata></v:shape>


But when I substitute the “11” with a filter and use the MaxMonth measure<o:p></o:p>


2016 ADJ NET SALES-YTD =CALCULATE(SUM([ADJUSTED NET SALES]), 'MONTHLYSALES 002'[CAL_YEAR]=2016,filter ('MONTHLYSALES 002', [PERIOD] <= [MAX MONTH]))<o:p></o:p>

I get the below results.<o:p></o:p>

[TABLE="width: 582"]
<colgroup><col width="268" style="width: 201pt; mso-width-source: userset; mso-width-alt: 9801;"> <col width="103" style="width: 77pt; mso-width-source: userset; mso-width-alt: 3766;" span="4"> <col width="97" style="width: 73pt; mso-width-source: userset; mso-width-alt: 3547;"> <tbody>[TR]
[TD="class: xl68, width: 268"][/TD]
[TD="class: xl69, width: 103"]2016 ADJ NET SALES-TOTAL[/TD]
[TD="class: xl69, width: 103"]2016 ADJ NET SALES-YTD[/TD]
[TD="class: xl69, width: 103"]2017 ADJ NET SALES- YTD[/TD]
[TD="class: xl70, width: 103"]YTD % CHNG[/TD]
[TD="width: 97"]MAX MONTH[/TD]
[/TR]
[TR]
[TD="class: xl71"]FLEA & TICK[/TD]
[TD="class: xl65, align: right"]$34,273,033[/TD]
[TD="class: xl65, align: right"]$34,273,033[/TD]
[TD="class: xl67, align: right"]$34,925,113[/TD]
[TD="class: xl66, align: right"]1.9 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: xl71"]HEALTH AND BEAUTY CARE[/TD]
[TD="class: xl65, align: right"]$7,262,615[/TD]
[TD="class: xl65, align: right"]$7,262,615[/TD]
[TD="class: xl67, align: right"]$8,012,576[/TD]
[TD="class: xl66, align: right"]10.3 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: xl71"]FORMULATED TREATS[/TD]
[TD="class: xl65, align: right"]$6,379,316[/TD]
[TD="class: xl65, align: right"]$6,379,316[/TD]
[TD="class: xl67, align: right"]$5,327,003[/TD]
[TD="class: xl66, align: right"]-16.5 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: xl71"]DENTAL[/TD]
[TD="class: xl65, align: right"]$1,103,680[/TD]
[TD="class: xl65, align: right"]$1,103,680[/TD]
[TD="class: xl67, align: right"]$1,022,124[/TD]
[TD="class: xl66, align: right"]-7.4 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: xl71"]ACCESSORIES AND TOYS[/TD]
[TD="class: xl65, align: right"]$229,835[/TD]
[TD="class: xl65, align: right"]$229,835[/TD]
[TD="class: xl67, align: right"]$195,077[/TD]
[TD="class: xl66, align: right"]-15.1 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: xl71"]NATURAL TREATS[/TD]
[TD="class: xl65, align: right"]$33,044[/TD]
[TD="class: xl65, align: right"]$33,044[/TD]
[TD="class: xl67, align: right"]$26,584[/TD]
[TD="class: xl66, align: right"]-19.5 %[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD="class: xl71"]WASTE MANAGEMENT & HOUSEBREAK[/TD]
[TD="class: xl65, align: right"]$31,189[/TD]
[TD="class: xl65, align: right"]$31,189[/TD]
[TD="class: xl67, align: right"]$11,783[/TD]
[TD="class: xl66, align: right"]-62.2 %[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD="class: xl71"]RAWHIDE[/TD]
[TD="class: xl65, align: right"]$31,445[/TD]
[TD="class: xl65, align: right"]$31,445[/TD]
[TD="class: xl67, align: right"]$4,574[/TD]
[TD="class: xl66, align: right"]-85.5 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: xl71"]Grand Total[/TD]
[TD="class: xl65, align: right"]$49,344,155[/TD]
[TD="class: xl65, align: right"]$49,344,155[/TD]
[TD="class: xl67, align: right"]$49,524,835[/TD]
[TD="class: xl66, align: right"]0.4 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
</tbody>[/TABLE]

<v:oval id="Oval_x0020_5" style="width: 66.75pt; height: 22.5pt; margin-top: 115.9pt; margin-left: 228.75pt; visibility: visible; position: absolute; z-index: 251659264; mso-wrap-style: square; mso-width-percent: 0; mso-height-percent: 0; mso-wrap-distance-left: 9pt; mso-wrap-distance-top: 0; mso-wrap-distance-right: 9pt; mso-wrap-distance-bottom: 0; mso-position-horizontal: absolute; mso-position-horizontal-relative: text; mso-position-vertical: absolute; mso-position-vertical-relative: text; mso-width-relative: margin; mso-height-relative: margin; v-text-anchor: middle;" filled="f" o:spid="_x0000_s1026" strokeweight="2pt" strokecolor="red" o:gfxdata="UEsDBBQABgAIAAAAIQC75UiUBQEAAB4CAAATAAAAW0NvbnRlbnRfVHlwZXNdLnhtbKSRvU7DMBSF
dyTewfKKEqcMCKEmHfgZgaE8wMW+SSwc27JvS/v23KTJgkoXFsu+P+c7Ol5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0yPZVdWDx
kwHii0k6zSF2ugbSL6Ek/2f7YZgUnr16WHT5RwTLpRcWoIwGMwdKV2edNS1dgYmGff0m3gAAAP//
AwBQSwECLQAUAAYACAAAACEAu+VIlAUBAAAeAgAAEwAAAAAAAAAAAAAAAAAAAAAAW0NvbnRlbnRf
VHlwZXNdLnhtbFBLAQItABQABgAIAAAAIQCtMD/xwQAAADIBAAALAAAAAAAAAAAAAAAAADYBAABf
cmVscy8ucmVsc1BLAQItABQABgAIAAAAIQAhiDh7vgIAAGUGAAAfAAAAAAAAAAAAAAAAACACAABj
bGlwYm9hcmQvZHJhd2luZ3MvZHJhd2luZzEueG1sUEsBAi0AFAAGAAgAAAAhAOFRNx/PBgAA5hsA
ABoAAAAAAAAAAAAAAAAAGwUAAGNsaXBib2FyZC90aGVtZS90aGVtZTEueG1sUEsBAi0AFAAGAAgA
AAAhAJxmRkG7AAAAJAEAACoAAAAAAAAAAAAAAAAAIgwAAGNsaXBib2FyZC9kcmF3aW5ncy9fcmVs
cy9kcmF3aW5nMS54bWwucmVsc1BLBQYAAAAABQAFAGcBAAAlDQAAAAA=
"><v:shape id="Picture_x0020_4" style="width: 468pt; height: 132.75pt; visibility: visible; mso-wrap-style: square;" type="#_x0000_t75" o:spid="_x0000_i1025"> <v:imagedata o:title="" src="file:///C:/Users/arundell/AppData/Local/Temp/msohtmlclip1/01/clip_image004.emz"></v:imagedata></v:shape><o:p></o:p></v:oval>


I want to be able to use the Max Month measure which isautomated, but get the results in the first table.
What am I doing wrong?

THANKS FOR THE HELP

 

Excel Facts

Can Excel fill bagel flavors?
You can teach Excel a new custom list. Type the list in cells, File, Options, Advanced, Edit Custom Lists, Import, OK
Jesus! My eyes!

This is really hard to follow, but you probably want to replace [Max Month] in your last measure with the actual text of the measure, to avoid context transition.
 
Upvote 0
Thanks gaz,
I agree that is brutal. I am not sure what happened with the post. I tried to paste a excel table that must have screwed it up.

Your suggestion worked. So that I can learn. What do you mean by context transition??
 
Upvote 0
To make it easier, I cleaned up the post.

I am new to this DAX language and I am sure the solution is a very simple one, but I would appreciate some help.

I have created two measures.

MAX MONTH=MONTH(MAX('MONTHLYSALES 002'[Date]))
2016 ADJ NET SALES-YTD= CALCULATE(SUM([ADJUSTED NET SALES]), 'MONTHLYSALES002'[CAL_YEAR]=2016,'MONTHLYSALES 002'[PERIOD]<=11)<o:p></o:p>

Which gives me the desired results in a Pivot table<o:p></o:p>
[TABLE="width: 582"]
<tbody>[TR]
[TD][/TD]
[TD]2016 ADJ NET SALES-TOTAL
[/TD]
[TD]2016 ADJ NET SALES-YTD
[/TD]
[TD]2017 ADJ NET SALES- YTD
[/TD]
[TD]YTD % CHNG
[/TD]
[TD]MAX MONTH
[/TD]
[/TR]
[TR]
[TD]FLEA & TICK
[/TD]
[TD="align: right"]$34,273,033
[/TD]
[TD="align: right"]$32,747,351
[/TD]
[TD="align: right"]$34,925,113
[/TD]
[TD="align: right"]6.7 %
[/TD]
[TD="align: right"]11
[/TD]
[/TR]
[TR]
[TD]HEALTH AND BEAUTY CARE
[/TD]
[TD="align: right"]$7,262,615
[/TD]
[TD="align: right"]$6,407,594
[/TD]
[TD="align: right"]$8,012,576
[/TD]
[TD="align: right"]25.0 %
[/TD]
[TD="align: right"]11
[/TD]
[/TR]
[TR]
[TD]FORMULATED TREATS
[/TD]
[TD="align: right"]$6,379,316
[/TD]
[TD="align: right"]$6,071,751
[/TD]
[TD="align: right"]$5,327,003
[/TD]
[TD="align: right"]-12.3 %
[/TD]
[TD="align: right"]11
[/TD]
[/TR]
[TR]
[TD]DENTAL
[/TD]
[TD="align: right"]$1,103,680
[/TD]
[TD="align: right"]$1,017,407
[/TD]
[TD="align: right"]$1,022,124
[/TD]
[TD="align: right"]0.5 %
[/TD]
[TD="align: right"]11
[/TD]
[/TR]
[TR]
[TD]ACCESSORIES AND TOYS
[/TD]
[TD="align: right"]$229,835
[/TD]
[TD="align: right"]$211,170
[/TD]
[TD="align: right"]$195,077
[/TD]
[TD="align: right"]-7.6 %
[/TD]
[TD="align: right"]11
[/TD]
[/TR]
[TR]
[TD]NATURAL TREATS
[/TD]
[TD="align: right"]$33,044
[/TD]
[TD="align: right"]$33,044
[/TD]
[TD="align: right"]$26,584
[/TD]
[TD="align: right"]-19.5 %
[/TD]
[TD="align: right"]8
[/TD]
[/TR]
[TR]
[TD]WASTE MANAGEMENT & HOUSEBREAK
[/TD]
[TD="align: right"]$31,189
[/TD]
[TD="align: right"]$28,108
[/TD]
[TD="align: right"]$11,783
[/TD]
[TD="align: right"]-58.1 %
[/TD]
[TD="align: right"]10
[/TD]
[/TR]
[TR]
[TD]RAWHIDE
[/TD]
[TD="align: right"]$31,445
[/TD]
[TD="align: right"]$31,445
[/TD]
[TD="align: right"]$4,574
[/TD]
[TD="align: right"]-85.5 %
[/TD]
[TD="align: right"]11
[/TD]
[/TR]
[TR]
[TD]Grand Total
[/TD]
[TD="align: right"]$49,344,155
[/TD]
[TD="align: right"]$46,547,870
[/TD]
[TD="align: right"]$49,524,835
[/TD]
[TD="align: right"]6.4 %
[/TD]
[TD="align: right"]11
[/TD]
[/TR]
</tbody>[/TABLE]

<v:shapetype id="_x0000_t75" coordsize="21600,21600" o:spt="75" o:preferrelative="t" path="m@4@5l@4@11@9@11@9@5xe" filled="f" stroked="f"><v:stroke joinstyle="miter"> <v:formulas> <v:f eqn="if lineDrawn pixelLineWidth 0"> <v:f eqn="sum @0 1 0"> <v:f eqn="sum 0 0 @1"> <v:f eqn="prod @2 1 2"> <v:f eqn="prod @3 21600 pixelWidth"> <v:f eqn="prod @3 21600 pixelHeight"> <v:f eqn="sum @0 0 1"> <v:f eqn="prod @6 1 2"> <v:f eqn="prod @7 21600 pixelWidth"> <v:f eqn="sum @8 21600 0"> <v:f eqn="prod @7 21600 pixelHeight"> <v:f eqn="sum @10 21600 0"> </v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:f></v:formulas><v:path o:extrusionok="f" gradientshapeok="t" o:connecttype="rect"> <o:lock v:ext="edit" aspectratio="t"></o:lock></v:path></v:stroke></v:shapetype><v:shape id="Picture_x0020_3" style="width: 468pt; height: 132.75pt; visibility: visible; mso-wrap-style: square;" type="#_x0000_t75" o:spid="_x0000_i1026"> <v:imagedata o:title="" src="file:///C:/Users/arundell/AppData/Local/Temp/msohtmlclip1/01/clip_image001.emz"></v:imagedata></v:shape>


But when I substitute the “11” with a filter and use the MaxMonth measure<o:p></o:p>

2016 ADJ NET SALES-YTD =CALCULATE(SUM([ADJUSTED NET SALES]), 'MONTHLYSALES 002'[CAL_YEAR]=2016,filter ('MONTHLYSALES 002', [PERIOD] <= [MAX MONTH]))<o:p></o:p>

I get the below results.
[TABLE="class: cms_table, width: 582"]
<tbody>[TR]
[TD="class: cms_table_xl68, width: 268"][/TD]
[TD="class: cms_table_xl69, width: 103"]2016 ADJ NET SALES-TOTAL[/TD]
[TD="class: cms_table_xl69, width: 103"]2016 ADJ NET SALES-YTD[/TD]
[TD="class: cms_table_xl69, width: 103"]2017 ADJ NET SALES- YTD[/TD]
[TD="class: cms_table_xl70, width: 103"]YTD % CHNG[/TD]
[TD="width: 97"]MAX MONTH[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl71"]FLEA & TICK[/TD]
[TD="class: cms_table_xl65, align: right"]$34,273,033[/TD]
[TD="class: cms_table_xl65, align: right"]$34,273,033[/TD]
[TD="class: cms_table_xl67, align: right"]$34,925,113[/TD]
[TD="class: cms_table_xl66, align: right"]1.9 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl71"]HEALTH AND BEAUTY CARE[/TD]
[TD="class: cms_table_xl65, align: right"]$7,262,615[/TD]
[TD="class: cms_table_xl65, align: right"]$7,262,615[/TD]
[TD="class: cms_table_xl67, align: right"]$8,012,576[/TD]
[TD="class: cms_table_xl66, align: right"]10.3 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl71"]FORMULATED TREATS[/TD]
[TD="class: cms_table_xl65, align: right"]$6,379,316[/TD]
[TD="class: cms_table_xl65, align: right"]$6,379,316[/TD]
[TD="class: cms_table_xl67, align: right"]$5,327,003[/TD]
[TD="class: cms_table_xl66, align: right"]-16.5 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl71"]DENTAL[/TD]
[TD="class: cms_table_xl65, align: right"]$1,103,680[/TD]
[TD="class: cms_table_xl65, align: right"]$1,103,680[/TD]
[TD="class: cms_table_xl67, align: right"]$1,022,124[/TD]
[TD="class: cms_table_xl66, align: right"]-7.4 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl71"]ACCESSORIES AND TOYS[/TD]
[TD="class: cms_table_xl65, align: right"]$229,835[/TD]
[TD="class: cms_table_xl65, align: right"]$229,835[/TD]
[TD="class: cms_table_xl67, align: right"]$195,077[/TD]
[TD="class: cms_table_xl66, align: right"]-15.1 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl71"]NATURAL TREATS[/TD]
[TD="class: cms_table_xl65, align: right"]$33,044[/TD]
[TD="class: cms_table_xl65, align: right"]$33,044[/TD]
[TD="class: cms_table_xl67, align: right"]$26,584[/TD]
[TD="class: cms_table_xl66, align: right"]-19.5 %[/TD]
[TD="align: right"]8[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl71"]WASTE MANAGEMENT & HOUSEBREAK[/TD]
[TD="class: cms_table_xl65, align: right"]$31,189[/TD]
[TD="class: cms_table_xl65, align: right"]$31,189[/TD]
[TD="class: cms_table_xl67, align: right"]$11,783[/TD]
[TD="class: cms_table_xl66, align: right"]-62.2 %[/TD]
[TD="align: right"]10[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl71"]RAWHIDE[/TD]
[TD="class: cms_table_xl65, align: right"]$31,445[/TD]
[TD="class: cms_table_xl65, align: right"]$31,445[/TD]
[TD="class: cms_table_xl67, align: right"]$4,574[/TD]
[TD="class: cms_table_xl66, align: right"]-85.5 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
[TR]
[TD="class: cms_table_xl71"]Grand Total[/TD]
[TD="class: cms_table_xl65, align: right"]$49,344,155[/TD]
[TD="class: cms_table_xl65, align: right"]$49,344,155[/TD]
[TD="class: cms_table_xl67, align: right"]$49,524,835[/TD]
[TD="class: cms_table_xl66, align: right"]0.4 %[/TD]
[TD="align: right"]11[/TD]
[/TR]
</tbody>[/TABLE]


The measure for 2016 Adj Net Sales YTD = 2016 Adj Net Sales Total


I want to be able to use the Max Month measure which is automated, but get the results in the first table. What am I doing wrong?

THANKS FOR THE HELP
 
Upvote 0
This might be a bigger topic than I can can veer in a short forum post from my phone...

If we just look at the filter part as that’s where the problem is.

filter ('MONTHLYSALES 002', [PERIOD] <= [MAX MONTH] )

Naively we might expect this to return all the rows in MonthlySales 002 Table where the date is less than the largest date selected in the filter (NB, I believe PERIOD is a column, always use the table name in such cases so it is clear which is a column and which is a measure). How it actually works is as follows:

1. Iterate through every row in the table that are not filtered out by your current filters.
2. Check to see if the criteria in the second clause ie PERIOD < MAX DATE and if not, exclude the row.
2a. If MAX DATE is written out in full then, as MAX is an aggregator and returns the maximum value in the filter context, rows are excluded if their dates are above the maximum of the filters then exclude (this is the desired result).
2b. If the MAX DATE measure is used, then context transition is carried out automatically (because it is a measure). Any existing row context is converted to a filter context. The row context is the row that is currently being iterated and it is converted to a filter context; the Max Date therefore returns the max date of the current row only. Clearly the date for every row is less than or equal to the max of itself so gets included.
 
Upvote 0

Forum statistics

Threads
1,224,818
Messages
6,181,152
Members
453,021
Latest member
Justyna P

We've detected that you are using an adblocker.

We have a great community of people providing Excel help here, but the hosting costs are enormous. You can help keep this site running by allowing ads on MrExcel.com.
Allow Ads at MrExcel

Which adblocker are you using?

Disable AdBlock

Follow these easy steps to disable AdBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the icon in the browser’s toolbar.
2)Click on the "Pause on this site" option.
Go back

Disable AdBlock Plus

Follow these easy steps to disable AdBlock Plus

1)Click on the icon in the browser’s toolbar.
2)Click on the toggle to disable it for "mrexcel.com".
Go back

Disable uBlock Origin

Follow these easy steps to disable uBlock Origin

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back

Disable uBlock

Follow these easy steps to disable uBlock

1)Click on the icon in the browser’s toolbar.
2)Click on the "Power" button.
3)Click on the "Refresh" button.
Go back
Back
Top