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
Ritesh_Air
Post Patron
Post Patron

Reverse a Measure from another measure

Hi,

I am trying to do a cross sale. Where whatever value comes in the first column needs to be in reverse orders.

I have only 2 rows. 

 

In the column below for Cross_Sale column I should get :

 

Row 1 :103

Row2 : 51

 

Not sure why it is taking the "total" into consideration.

 

Reverse a Measure.PNG

 

 

Here is my formula:

 

Cross_Sales = 

VAR RANK_desc =
	RANKX (	
		ALLSELECTED (crop_master[CROP]),
		[Increase_SALES_BOTH_CROPS],
		,
		asc
	)
return
	CALCULATE (
		([INCREASE_SALES_BOTH_CROPS]),
		TOPN (
			RANK_DESC,
			SUMMARIZE (
			   ALLSELECTED (crop_master[CROP]),
			   crop_master[CROP],
			    "TOTAL GOOD", [INCREASE_SALES_BOTH_CROPS]
			),
			[crop], DESC
)
)	

 Thanks,

Ritesh

1 ACCEPTED SOLUTION
mahoneypat
Employee
Employee

You are seeing the same as the total because that one has a Rank of 2, so your TOPN is keeping the top 2 rows (both in your case).  Please see if this expression gets your exprected cross sales result.  It will calculate the total sales of all the crops except the one on that row.

 

Crop Cross Sales =
VAR thiscrop =
VALUES ( crop_master[CROP] )
VAR allcrops =
ALLSELECTED ( crop_master[CROP] )
RETURN
CALCULATE ( [Increase_SALES_BOTH_CROPS], EXCEPT ( allcrops, thiscrop ) )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


View solution in original post

5 REPLIES 5
parry2k
Super User
Super User

@Ritesh_Air see attached, I added an index column in PQ and then measure, in attached, see a table called "Cross"

 

I would  Kudos if my solution helped. 👉 If you can spend time posting the question, you can also make efforts to give Kudos whoever helped to solve your problem. It is a token of appreciation!

Visit us at https://perytus.com, your one-stop-shop for Power BI-related projects/training/consultancy.

 



Subscribe to the @PowerBIHowTo YT channel for an upcoming video on List and Record functions in Power Query!!

Learn Power BI and Fabric - subscribe to our YT channel - Click here: @PowerBIHowTo

If my solution proved useful, I'd be delighted to receive Kudos. When you put effort into asking a question, it's equally thoughtful to acknowledge and give Kudos to the individual who helped you solve the problem. It's a small gesture that shows appreciation and encouragement! ❤


Did I answer your question? Mark my post as a solution. Proud to be a Super User! Appreciate your Kudos 🙂
Feel free to email me with any of your BI needs.

mahoneypat
Employee
Employee

You are seeing the same as the total because that one has a Rank of 2, so your TOPN is keeping the top 2 rows (both in your case).  Please see if this expression gets your exprected cross sales result.  It will calculate the total sales of all the crops except the one on that row.

 

Crop Cross Sales =
VAR thiscrop =
VALUES ( crop_master[CROP] )
VAR allcrops =
ALLSELECTED ( crop_master[CROP] )
RETURN
CALCULATE ( [Increase_SALES_BOTH_CROPS], EXCEPT ( allcrops, thiscrop ) )

 

If this works for you, please mark it as the solution.  Kudos are appreciated too.  Please let me know if not.

Regards,

Pat





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat 

 

 

That begs one more question. Could I have done it with the path I was going? Using TopN function, likesomehow remove TOTAL from the equation?

 

Thanks,

Ritesh

You probably could have.  You can calculate the overall total and then subtract the sales for that row to get same result.  But the Except route does it simpler.

 

Regards,

Pat

 





Did I answer your question? Mark my post as a solution! Kudos are also appreciated!

To learn more about Power BI, follow me on Twitter or subscribe on YouTube.


@mahoneypa HoosierBI on YouTube


@mahoneypat Wow! That was such a simple, yet elegant and powerful solution. Thank you so much!

 

@parry2k Thanks Parry as well 🙂

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.