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
sanshushu
Frequent Visitor

Help, friends. Is there a better way to implement this data model?

Help, friends. Is there a better way to implement this data model?

My English level is not good, now use translation tools, if you have not understand the place, welcome to leave a message oh.


I built a data model to measure the return rate of the stock market. The data sources include [Date], [Opening], [Lowest], [Maximum], [Close],

The following data is a function I wrote:

 

[Entrustment buy price] and [Entrustment sell price] for the next trading day

Entrustment buy price = [Close ]*(1-parameter)

Entrustment sell price = [Close ]*(1+parameter)


Successful device purchase when [Entrustment Buy price] > [Lowest] of next trading day;

Successful consignment sale occurs when [Entrustment sell price] is < [Maximum] on the next trading day

;


I wrote the judgment company as follows:

[Entrustment buy result] =

var _minnext = MINX(FILTER('table',[Date]>EARLIER('table'[Date]) ),[Date])

var _weimai = AVERAGEX(FILTER('table',[Date]=_minnext ),[Lowest])

return IF(_weimai<[Entrustment buy price],"Successful entrusted purchase","")


[Entrustment sell result] =

var _minnext = MINX(FILTER('table',[Date]>EARLIER('table'[Date]) ),[Date])

var _weimai = AVERAGEX(FILTER('table',[Date]=_minnext ),[Maximum])

return IF(_weimai>[Entrustment sell price],"Successful consignment sale","")


When Successful discrepancy purchase, only Successful consignment sale can continue to buy stocks;


[Position to judge] indicates whether it is available for purchase.


Position to judge =

var _wmjsjmax = MAXX(FILTER('table', [Date]

var _wmcsjmax = MAXX(FILTER('table',[Date]sale" ),[Date])

return

If (_wmcsjmax < _wmjsjmax, 1, 0)


[Position the results] represents the time node of (Successful discrepancy purchase) or (Successful consignment sale),


Position the results =

var _datemin = minx(FILTER('table', [Date]>EARLIER('FILTER'[Date])),[Date])

var _val = SUMX(FILTER('table', [Date]=_datemin),Position to judge])

return [Position to judge]-_val


Cost of purchase = ROUND( if([Position the results]=-1,[Entrustment buy price],BLANK()),2)


Sell price = ROUND( if([Position the results]=1,[Entrustment sell price],BLANK()),2)

 

Trading profit =

var _maxdate = MAXX(FILTER('table', [Date]BLANK()),[Date])

var _val = SUMX(FILTER('table', [Date] = _maxdate),[Cost of purchase])

return IF([Sell price]=BLANK(),BLANK(),DIVIDE([Sell price]-_val,_val))

 

_________________________________________________________________________________________


The calculated value of [Entrustment buy price] and [Entrustment sell price] is calculated through (parameters), but not through (create measures). Therefore, (parameter) can only be manually adjusted.

I hope to know different (parameters). When the value of (parameters) is what, Trading profit can be maximized.


And what better way to implement this data model?


Thank you for your help

 

 

DateOpeningLowestMaximumClose Entrustment buy priceEntrustment sell priceEntrustment buy resultEntrustment sell resultPosition to judgePosition the resultsCost of purchaseSell priceTrading profit
2021/4/2127.65127.52130.72130.28126.39134.17Successful entrusted purchase 0-1126.39  
2021/4/6130.36125.92130.59127.92123.84132Successful entrusted purchase 10   
2021/4/7128.3123.82130.21130.15126.24134.06Successful entrusted purchaseSuccessful consignment sale11 134.066.07%
2021/4/8126.15126.13134.45134.13129.85138.41  00   
2021/4/9133.05130.14133.33131.35127.33135.37Successful entrusted purchase 0-1127.33  
2021/4/12131.26127.29131.36129.09125.03133.15  10   
2021/4/13129.96129.22131.38130.44126.72134.16  10   
2021/4/14129.28127.07131.28129.69126.34133.04  10   
2021/4/15129.03127.41130.48129.4126.86131.94Successful entrusted purchase 10   
2021/4/16130.75125.59130.75127.67124.85130.49 Successful consignment sale11 130.492.48%
2021/4/19128.35126.36130.55129.39126.5132.28  00   
2021/4/20129.21128.19130.73128.41125.48131.34  00   
2021/4/21127.67127.02129.18128.32125.7130.94Successful entrusted purchase 0-1125.7  
2021/4/22128.57124.59129.13125.05122.27127.83 Successful consignment sale11 127.831.69%
2021/4/23125.05124.6131130.59127.46133.72Successful entrusted purchase 0-1127.46  
2021/4/26131.65123.81132.16123.83120.27127.39  10   
2021/4/27124.05123.82125.32124.85121.4128.3  10   
2021/4/28124.72121.52124.74123.44119.86127.02 Successful consignment sale11 127.02-0.35%
2021/4/29123.82123.44128.59126.9123.1130.7 Successful consignment sale00   
2021/4/30129.98127.28131.5129.59126.06133.12Successful entrusted purchase 0-1126.06  
2021/5/6129.59125.04131.05126.12123.03129.21Successful entrusted purchase 10   
2021/5/7125.98121.02127.04121.58117.93125.23  10   
2021/5/10121.62120.28122.9121.98118.4125.56 Successful consignment sale11 125.56-0.40%
4 REPLIES 4
v-yiruan-msft
Community Support
Community Support

Hi @sanshushu ,

I'm sorry I don't quite understand what you are looking for. Are you trying to get a dynamic parameter to get a maximum trading profit? If so, please refer to the following blog on using what if parameter to achieve it.

Make your data dynamic with Power BI “What if Analysis” Pt1

Power BI What If Parameter for Getting the Sales of X months ago: Use Case Scenario

If the above one can't help you, please provide your expected result with more details(backend logic, special examples etc.). Thank you.

Best Regards

Community Support Team _ Rena
If this post helps, then please consider Accept it as the solution to help the other members find it more quickly.

Thanks for your reply, my friend.

My model looks something like this

One problem is that "what if parameter" is only "create measures", not "calculated columns".

 


Link: https://pan.baidu.com/s/15778Vy52FHaWXOVD4FsfHw 

Extraction code: 1234

sanshushu
Frequent Visitor

help

I need you my friend

help

 

sanshushu
Frequent Visitor


Because of the translation tool, this is a few errors,

See the screenshot for the correct code. Thank you very much!

 

微信图片_20210927215949.png

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.