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

Register now to learn Fabric in free live sessions led by the best Microsoft experts. From Apr 16 to May 9, in English and Spanish.

Reply
Anonymous
Not applicable

Measure that groups sales

Hello people!

 

I'm needing a bit of help.

 

I'm trying to make a mesaure that groups sales by the first 3 letters of a description.

 

In my fact table I have sales open by IdZonaGestion (examples: "ARG-OTR", "ARG-ROE", etc). The sum of all sales of a specific period represents market sales, while the sales of same period but only of those IdZonaGestion wich last 3 letters are not "OTR" represents my sales.

 

So, in my scenario, I need to perform a report thats opened by IdZonaGestion showing only my sales (all the IdZonaGestion that not finish in "OTR") and with a column that has a mesaure that displays the participation of my sales in the market.

 

The sales of market are by country, so, in these case the SUM of sales of the IdZonaGestion that starts with "ARG" (Argentina) are the market sakles, and the SUM of sales of the IdZonaGestion that do not finish in "OTR" are my sales.

 

What I have done so far, is this:
Sin título.png

 

And some data sample:

IDIdPeriodoIdAnioIdMesIdPaisPresentacionCorporacionLaboratorioIdCompaniaIdClaseTerapeutica1IdClaseTerapeutica2IdClaseTerapeutica3IdClaseTerapeutica4MercadoMercadoPorTipoIdMarcaMarcaSubFamiliaAnioLanzamientoConcentracionFechaLanzamientoMATUnidadesSalidasImporteVendidoImporteVendidoUSDIdPaisIMSGrupoIdZonaGestion
120120220122ARG       3-tc Tabl Recubie 150 Mg X 60Glaxosmithkli.corpGlaxosmithkline PhARG-OTRJJ05J05CJ05C1EticoMarca10523-tcLamivudine1996150 MG[Legacy Products]93885,29992894,24063ArgentinaGLAXOSMITHKLI CORPARG-OTR
220120220122ARG       5 Asa Sobres 2 G X 30DominguezDominguezARG-OTRAA07A07EA07E1EticoMarca10535 AsaMesalazine20162 G[Legacy Products]000ArgentinaDOMINGUEZARG-OTR
320120220122ARG       8-horas Tabl Recubie 1 Mg X 30Elea CorpEleaARG-OTRNN05N05BN05B1EticoMarca93318-horasEszopiclone20071 MG[Legacy Products]44812902,40392969,61728ArgentinaELEA CORPARG-OTR
420120220122ARG       A Sun Fluide 50+ Envase 40 Ml X 1DispolabDispolabARG-OTRDD02D02AD02A0PopularMarca17041A Sun Fluide 50+Ectoin + Titanium + Vitamin E2013[N/A]Launched in MAT Ene.-14000ArgentinaDISPOLABARG-OTR
520120220122ARG       A-acido Emoliente Crema 25 Mg 30 G X 1DominguezDominguezARG-OTRDD05D05XD05X0EticoMarca1058A-acido EmolienteTretinoin199325 MG[Legacy Products]312219,28941510,79165ArgentinaDOMINGUEZARG-OTR
620120220122ARG       A-derma Exomega Leche 400 Ml X 1Pierre FabrePierre Fabre DermoARG-OTRDD02D02AD02A0PopularMarca37981A-derma ExomegaAvena Sativa + Butyrospermum Parkii + Glycerol2009[N/A][Legacy Products]50138592,01968882,33922ArgentinaPIERRE FABREARG-OTR
720120220122ARG       A-vitel Pant Solar Crema Fps36 120 G X 1MedipharmaMedipharmaARG-OTRDD02D02AD02A0PopularMarca14293A-vitel Pant SolarRetinol2003[N/A][Legacy Products]123,87999655,49622ArgentinaMEDIPHARMAARG-OTR

 

What I guess, is that I need to group the sales in measure "Ventas USD IMS Mercado", so all the IdZonaGestion that start with same first 3 letters have same value. This, with the porpuse of making later a mesaure for the participation.

 

Resuming, I imagine that in the table that I share, I would have "IdZonaGestion", "Ventas USD IMS Propio" (my sales), and "Ventas USD IMS Mercado" (sum of market sales, including me), seeing only the "IdZonaGestion" that are mine (<> from "OTR") but with the total sales of market in last column ("Ventas USD IMS Mercado").

 

Hope I'm clear and somebody can help me with this.

 

Thanks in advance.

1 ACCEPTED SOLUTION

@Anonymous

 

Check the PBIX.

 

https://drive.google.com/file/d/0B95C8CKdTZE3ZVdvY2lNR2YyczA/view?usp=sharing

 

IMS.png

 

ImporteVendidoTotal =
VAR PAIS =
    DISTINCT ( 'Zona-Gestión'[Pais] )
RETURN
    IF (
        HASONEVALUE ( 'Zona-Gestión'[IdZonaGestion] ),
        IF (
            SEARCH ( "-OTR", VALUES ( 'Zona-Gestión'[IdZonaGestion] ),, BLANK () )
                = BLANK (),
            CALCULATE (
                SUM ( 'Ventas IMS'[ImporteVendidoUSD] ),
                FILTER ( ALLSELECTED ( 'Ventas IMS' ), 'Ventas IMS'[IdPaisIMS] = PAIS ),
                ALLEXCEPT ( 'Ventas IMS', 'Ventas IMS'[IdAnio], 'Ventas IMS'[IdMes] )
            )
        ),
        SUM ( 'Ventas IMS'[ImporteVendidoUSD] )
    )

 

Regards

 

Victor

Lima - Peru




Lima - Peru

View solution in original post

11 REPLIES 11
Vvelarde
Community Champion
Community Champion

@Anonymous

 

 

Hi, What option do you want to see? or a different ?

 

Img.png

 

 

Regards

 

Victor

Lima - Peru




Lima - Peru
Anonymous
Not applicable

Hi @Vvelarde, thanks for your reply.

 

It should be like this:

 Ventas USD IMS PropioVentas USD IMS Mercado%
ARG-POE5537,48638619,970,86710098
ARG-RAY2533,67638619,970,39674143

 

Ventas USD IMS Mercado must sum all sales from "ARG", including "ARG-OTR".

 

Thanks in advance.

@Anonymous

 

Hi, Please check the PBIX. 

 

https://drive.google.com/file/d/0B95C8CKdTZE3MjYtRG8zckp6Nkk/view?usp=sharing

 

Regards

 

Victor

Lima - Peru




Lima - Peru
Anonymous
Not applicable

@Vvelarde

 

This is the result when applying the ALL function:

Sin título1.png

 

I get the same value (the grand total) for every IdZonaGestion. But what I really need are something like subtotals, one for each country ("ARG", "BRA", "VEN", etc.)

 

What should we change in the mesaure to make this possible?

@Anonymous

 

Hi, The more simple way is 

 

modify the measure: 

ImporteVendidoTotal = CALCULATE(SUM(Table1[ImporteVendidoUSD]),ALLEXCEPT(Table1,Table1[IdAnio],Table1[IdMes],Table1[IdPaisIMS]))

and add to table / matrix the Column Pais. If you don't want to see reduce his column Width.

 

Regards

 

Victor

 

 




Lima - Peru
Anonymous
Not applicable

Thanks @Vvelarde for your fast reply.

 

The problem is that I'm using the Matrix Preview object, that makes drill down in the dimentions added to rows. So, if I add Pais to the Matrix, the only thing that changes is that I have a new dimention analysis.

@Anonymous

 

Change the measures:

 

VentasUSDIMSPropio =
IF (
    SEARCH ( "-OTR", VALUES ( Table1[IdZonaGestion] ),, BLANK () ) = BLANK (),
    SUM ( Table1[ImporteVendidoUSD] ),
    BLANK ()
)

 

 

ImporteVendidoTotal =
VAR PAIS =
    VALUES ( Table1[IdPaisIMS] )
RETURN
    IF (
        SEARCH ( "-OTR", VALUES ( Table1[IdZonaGestion] ),, BLANK () ) = BLANK (),
        CALCULATE (
            SUM ( Table1[ImporteVendidoUSD] ),
            FILTER ( ALLSELECTED ( Table1 ), Table1[IdPaisIMS] = PAIS ),
            ALLEXCEPT ( Table1, Table1[IdAnio], Table1[IdMes] )
        )
    )

 

 

 

 

NewWat.png

 

Maybe need some adjusts accord to your model and visuals.

 

Regards

 

Victor

Lima - Peru




Lima - Peru
Anonymous
Not applicable

@Vvelarde

 

Here is the pbix: https://1drv.ms/u/s!AgDdItVNA18ZgW2QrC4tlIuMfZEO

 

It will probably be better if you can see it.

 

I left measure "Ventas USD IMS Mercado" with previous formula so it works, even though is not the result that I want.

 

Thanks!

@Anonymous

 

Check the PBIX.

 

https://drive.google.com/file/d/0B95C8CKdTZE3ZVdvY2lNR2YyczA/view?usp=sharing

 

IMS.png

 

ImporteVendidoTotal =
VAR PAIS =
    DISTINCT ( 'Zona-Gestión'[Pais] )
RETURN
    IF (
        HASONEVALUE ( 'Zona-Gestión'[IdZonaGestion] ),
        IF (
            SEARCH ( "-OTR", VALUES ( 'Zona-Gestión'[IdZonaGestion] ),, BLANK () )
                = BLANK (),
            CALCULATE (
                SUM ( 'Ventas IMS'[ImporteVendidoUSD] ),
                FILTER ( ALLSELECTED ( 'Ventas IMS' ), 'Ventas IMS'[IdPaisIMS] = PAIS ),
                ALLEXCEPT ( 'Ventas IMS', 'Ventas IMS'[IdAnio], 'Ventas IMS'[IdMes] )
            )
        ),
        SUM ( 'Ventas IMS'[ImporteVendidoUSD] )
    )

 

Regards

 

Victor

Lima - Peru




Lima - Peru
Anonymous
Not applicable

@Vvelarde, thank you so much for your help!

 

That whas awesome! Now I have everything working.

 

Greetings from Montevideo, Uruguay.

 

Have a nice day!

Anonymous
Not applicable

@Vvelarde

 

This is how the mesaure "Ventas USD IMS Mercado" looks like:

Ventas USD IMS Mercado = 
Var Pais = 
	VALUES('Ventas IMS'[IdPaisIMS])
	
RETURN
	IF(
		SEARCH(
			"-OTR";
			VALUES(
				'Ventas IMS'[IdZonaGestion]
			);;
			BLANK()
		) = BLANK();
		CALCULATE(
			SUM(
				'Ventas IMS'[ImporteVendidoUSD]
			);
			FILTER(
				ALLSELECTED(
					'Ventas IMS'
				);
				'Ventas IMS'[IdPaisIMS] = Pais
			);
			ALLEXCEPT(
				'Ventas IMS';
				'Ventas IMS'[Fecha]
			)
		)
	)

It hives me the next error:

 
MdxScript(Model) (2881, 31) Calculation error in measure 'Ventas IMS'[Ventas USD IMS Mercado]: A table of multiple values was supplied where a single value was expected.

 

Helpful resources

Announcements
Microsoft Fabric Learn Together

Microsoft Fabric Learn Together

Covering the world! 9:00-10:30 AM Sydney, 4:00-5:30 PM CET (Paris/Berlin), 7:00-8:30 PM Mexico City

PBI_APRIL_CAROUSEL1

Power BI Monthly Update - April 2024

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

April Fabric Community Update

Fabric Community Update - April 2024

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

Top Solution Authors