<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0" xmlns:atom="http://www.w3.org/2005/Atom" xmlns:dc="http://purl.org/dc/elements/1.1/">
  <channel>
    <title>DEV Community: Kevork Keheian</title>
    <description>The latest articles on DEV Community by Kevork Keheian (@kevorkkeheian).</description>
    <link>https://dev.to/kevorkkeheian</link>
    <image>
      <url>https://media2.dev.to/dynamic/image/width=90,height=90,fit=cover,gravity=auto,format=auto/https:%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Fuser%2Fprofile_image%2F291243%2F894307de-4bf0-460e-8ee7-f690a71a7da2.png</url>
      <title>DEV Community: Kevork Keheian</title>
      <link>https://dev.to/kevorkkeheian</link>
    </image>
    <atom:link rel="self" type="application/rss+xml" href="https://dev.to/feed/kevorkkeheian"/>
    <language>en</language>
    <item>
      <title>How to deploy streamlit app to Heroku</title>
      <dc:creator>Kevork Keheian</dc:creator>
      <pubDate>Mon, 20 Sep 2021 09:00:44 +0000</pubDate>
      <link>https://dev.to/kevorkkeheian/how-to-deploy-streamlit-app-to-heroku-khn</link>
      <guid>https://dev.to/kevorkkeheian/how-to-deploy-streamlit-app-to-heroku-khn</guid>
      <description>&lt;p&gt;Hello everyone,&lt;br&gt;
This is a step by step tutorial about how to deploy your Streamlit app to Heroku.&lt;/p&gt;
&lt;h2&gt;
  
  
  What is streamlit?
&lt;/h2&gt;

&lt;p&gt;Streamlit is an open-source python framework for Machine Learning and Data Science teams and individuals.&lt;br&gt;
See it yourself: &lt;a href="https://streamlit.io" rel="noopener noreferrer"&gt;https://streamlit.io&lt;/a&gt;&lt;br&gt;
You can deploy your app using streamlit sharing, but the problem is that you only have 3 apps with the free version.&lt;/p&gt;

&lt;p&gt;So what you will see now is how you can deploy your app to Heroku&lt;/p&gt;
&lt;h2&gt;
  
  
  Requirements:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;python&lt;/code&gt; installled&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;streamlit&lt;/code&gt; installed
(You can install streamlit using &lt;code&gt;pip install streamlit&lt;/code&gt;)&lt;/li&gt;
&lt;li&gt;
&lt;a href="https://github.com" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; account&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;Once the above are installed&lt;/p&gt;

&lt;p&gt;You can check their &lt;a href="https://docs.streamlit.io/en/stable/" rel="noopener noreferrer"&gt;documentation&lt;/a&gt; about creating you app.&lt;/p&gt;
&lt;h3&gt;
  
  
  And now it's time to deploy 🎇
&lt;/h3&gt;

&lt;p&gt;You need to add 2 additional files to your project.&lt;br&gt;
1- You need to add a &lt;strong&gt;setup.sh&lt;/strong&gt; file which is used to add shell commands inside the file.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight shell"&gt;&lt;code&gt;&lt;span class="nb"&gt;mkdir&lt;/span&gt; &lt;span class="nt"&gt;-p&lt;/span&gt; ~/.streamlit/
&lt;span class="nb"&gt;echo&lt;/span&gt; &lt;span class="s2"&gt;"&lt;/span&gt;&lt;span class="se"&gt;\&lt;/span&gt;&lt;span class="s2"&gt;
[server]&lt;/span&gt;&lt;span class="se"&gt;\n\&lt;/span&gt;&lt;span class="s2"&gt;
headless = true&lt;/span&gt;&lt;span class="se"&gt;\n\&lt;/span&gt;&lt;span class="s2"&gt;
port = &lt;/span&gt;&lt;span class="nv"&gt;$PORT&lt;/span&gt;&lt;span class="se"&gt;\n\&lt;/span&gt;&lt;span class="s2"&gt;
enableCORS = false&lt;/span&gt;&lt;span class="se"&gt;\n\&lt;/span&gt;&lt;span class="s2"&gt;
&lt;/span&gt;&lt;span class="se"&gt;\n\&lt;/span&gt;&lt;span class="s2"&gt;
"&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;&lt;/span&gt; ~/.streamlit/config.toml
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;Then add a new file called &lt;strong&gt;Procfile&lt;/strong&gt; and inside it paste the following code:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;web: sh setup.sh &amp;amp;&amp;amp; streamlit run app.py
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;And finally a &lt;strong&gt;requirements.txt&lt;/strong&gt; file&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight js-code-highlight"&gt;
&lt;pre class="highlight plaintext"&gt;&lt;code&gt;streamlit
matplotlib
numpy
pandas
&lt;/code&gt;&lt;/pre&gt;

&lt;/div&gt;



&lt;p&gt;and the other packages that you are using in your app.&lt;/p&gt;

&lt;p&gt;Now head over to &lt;a href="https://github.com" rel="noopener noreferrer"&gt;GitHub&lt;/a&gt; and create a new repository and publish your code to github. You can check this &lt;a href="https://medium.com/singapore-rails-learning-group/how-to-push-your-code-to-github-and-publish-your-first-page-8b0e1f4caf2a" rel="noopener noreferrer"&gt;article&lt;/a&gt; to see how you can do that.&lt;/p&gt;

&lt;p&gt;Once the code is on GitHub head over to &lt;a href="https://heroku.com" rel="noopener noreferrer"&gt;Heroku&lt;/a&gt; and create a new app:&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy8cqgbnnsvvvo8sgepor.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fy8cqgbnnsvvvo8sgepor.png" alt="Create a new app on Heroku"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Choose a name to your app and click "&lt;strong&gt;Create app&lt;/strong&gt;"&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fluevxt316fhugf8mes6b.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fluevxt316fhugf8mes6b.png" alt="Heroku - create a new app"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;You can leave the pipeline empty for the time being and choose "GitHub" as your deployment method.&lt;br&gt;
And in the &lt;strong&gt;Connect to GitHub&lt;/strong&gt; section choose your username/org, type the name of the repository and click search. After you click search you can see the repo, click on the &lt;strong&gt;Connect&lt;/strong&gt; button next to the repo.&lt;br&gt;
&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkpqhsz4y7lv14zi2v6ci.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fkpqhsz4y7lv14zi2v6ci.png" alt="Heroku - choose deployment method"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Once you click connect you can see at the end of the page The &lt;strong&gt;Manual deploy&lt;/strong&gt; section. Just click Deploy Branch and watch the magic happen.&lt;/p&gt;

&lt;p&gt;Once the deployment is finished you can check your app &lt;strong&gt;app-name&lt;/strong&gt;.heroku.com.&lt;br&gt;
In this case we chose &lt;strong&gt;streamlit-heroku-app&lt;/strong&gt; as our app name so if you need to navigate to streamlit-heroku-app.heroku.com to see the deployed streamlit app.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzanl8gtpwrieb84epafj.png" class="article-body-image-wrapper"&gt;&lt;img src="https://media.dev.to/dynamic/image/width=800%2Cheight=%2Cfit=scale-down%2Cgravity=auto%2Cformat=auto/https%3A%2F%2Fdev-to-uploads.s3.amazonaws.com%2Fuploads%2Farticles%2Fzanl8gtpwrieb84epafj.png" alt="Heroku - manaul deployment"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;&lt;em&gt;Note: the app is no longer available on heroku&lt;/em&gt;&lt;/p&gt;

</description>
      <category>python</category>
      <category>streamlit</category>
      <category>heroku</category>
    </item>
    <item>
      <title>Writing DAX Formulas</title>
      <dc:creator>Kevork Keheian</dc:creator>
      <pubDate>Thu, 13 Aug 2020 10:43:02 +0000</pubDate>
      <link>https://dev.to/kevorkkeheian/writing-dax-formulas-i5a</link>
      <guid>https://dev.to/kevorkkeheian/writing-dax-formulas-i5a</guid>
      <description>&lt;h2&gt;
  
  
  A - Introduction
&lt;/h2&gt;

&lt;p&gt;Every Dax formula, similar to programming variables should be defined/declared by a name and followed by the formula/value.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;Calculation&lt;/span&gt; &lt;span class="nx"&gt;name&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt;&lt;span class="nx"&gt;DAX&lt;/span&gt; &lt;span class="nx"&gt;formula&lt;/span&gt;&lt;span class="o"&gt;&amp;gt;&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h4&gt;
  
  
  For example:
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight javascript"&gt;&lt;code&gt;&lt;span class="nx"&gt;Order&lt;/span&gt; &lt;span class="nx"&gt;Type&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="dl"&gt;"&lt;/span&gt;&lt;span class="s2"&gt;Allocation&lt;/span&gt;&lt;span class="dl"&gt;"&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Here, the &lt;code&gt;Order Type&lt;/code&gt; is the name of the DAX formula and &lt;code&gt;"Allocation"&lt;/code&gt; is the &lt;strong&gt;value&lt;/strong&gt; or &lt;code&gt;Order Type&lt;/code&gt;.&lt;/p&gt;



&lt;h2&gt;
  
  
  B - Reminder
&lt;/h2&gt;

&lt;p&gt;As we mentioned &lt;a href="https://dev.to/kevorkkeheian/introduction-5ap8"&gt;in the introduction&lt;/a&gt; that each &lt;strong&gt;DAX formula&lt;/strong&gt;, whether it is a &lt;em&gt;calculated column&lt;/em&gt;, &lt;em&gt;calculated table&lt;/em&gt; or a &lt;em&gt;measure&lt;/em&gt; returns a &lt;strong&gt;value&lt;/strong&gt;.&lt;br&gt;
In other words "Allocation" is the returned value.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--V2kXmP3J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dh6ncvcxatqq6hc9xy0t.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--V2kXmP3J--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/dh6ncvcxatqq6hc9xy0t.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;This DAX formula is considered as a &lt;strong&gt;measure&lt;/strong&gt;. So, whenever we drag this measure into a values field, it will return the value "Allocated" to each field of the visual.&lt;/p&gt;

&lt;p&gt;So the returned result of a &lt;strong&gt;DAX&lt;/strong&gt; will be &lt;code&gt;"Allocation"&lt;/code&gt; for each row.&lt;/p&gt;
&lt;h2&gt;
  
  
  C - Referring a Table
&lt;/h2&gt;

&lt;p&gt;With DAX you can duplicate a table or a column using the same method as the above, but instead of a text inside a quotation you use the name of the table.&lt;/p&gt;
&lt;h4&gt;
  
  
  For Example:
&lt;/h4&gt;

&lt;p&gt;Let's suppose that you have a table called &lt;code&gt;Sales&lt;/code&gt; in your model. And you want to duplicate the table using a Calculated Table you will use the below formula:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Sales&lt;/span&gt; &lt;span class="n"&gt;Orders&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="n"&gt;Sales&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--yAzyyl5n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2gif7sa7qva8uksoh1l6.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--yAzyyl5n--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/2gif7sa7qva8uksoh1l6.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;Here the value or Sales Order which is the &lt;code&gt;Sales&lt;/code&gt; table that was already in the model does not need single quotes.&lt;/p&gt;

&lt;p&gt;Single quotes are needed when the value is a reserved word such as &lt;code&gt;Date&lt;/code&gt; or the table name does not include embedded spaces.&lt;br&gt;
EX:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Sales&lt;/span&gt; &lt;span class="n"&gt;Orders&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;Sales&lt;/span&gt; &lt;span class="n"&gt;Table&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Sales&lt;/span&gt; &lt;span class="n"&gt;Dates&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="err"&gt;'&lt;/span&gt;&lt;span class="n"&gt;Date&lt;/span&gt;&lt;span class="err"&gt;'&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;h2&gt;
  
  
  D - Referring a Column
&lt;/h2&gt;

&lt;p&gt;Referred Columns in a formula should be enclosed within square brackets.&lt;/p&gt;

&lt;h4&gt;
  
  
  example:
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Total&lt;/span&gt; &lt;span class="n"&gt;Sales&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;([&lt;/span&gt;&lt;span class="n"&gt;Amount&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;In the above example the value in the &lt;code&gt;SUM&lt;/code&gt; function is the column name.&lt;br&gt;
The column names are unique in the table. Some references tell you that you can use the column without preceding the table name.&lt;br&gt;
But, to improve the readability of your formulas, it is preferable  that the column reference precedes with its table name.&lt;/p&gt;
&lt;h4&gt;
  
  
  example:
&lt;/h4&gt;


&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Total&lt;/span&gt; &lt;span class="n"&gt;Sales&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Sales&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Amount&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;


&lt;p&gt;Another reason for preceding the table name in a column reference formula is that you never know when you will update your model. As we mentioned earlier, the column name is always unique in a table, but can be found multiple times in a model which includes multiple tables.&lt;/p&gt;
&lt;h2&gt;
  
  
  E - Referring a Measure:
&lt;/h2&gt;

&lt;p&gt;Finally, you can refer a measure in your formula.&lt;br&gt;
Let's suppose that we have the below column referring formulas (they are called measures):&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Total&lt;/span&gt; &lt;span class="n"&gt;Sales&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Sales&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Amount&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;





&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Total&lt;/span&gt; &lt;span class="n"&gt;Purchases&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Purchases&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Amount&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And you want to calculate the difference between &lt;code&gt;Sales amount&lt;/code&gt; and &lt;code&gt;Purchase Amount&lt;/code&gt;.&lt;br&gt;
To do this there are multiple ways:&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Revenue&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="nf"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Sales&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Amount&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="nf"&gt;SUM&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;Purchase&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Amount&lt;/span&gt;&lt;span class="p"&gt;])&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;or&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Revenue&lt;/span&gt;&lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Total&lt;/span&gt; &lt;span class="n"&gt;Sales&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Total&lt;/span&gt; &lt;span class="n"&gt;Purchases&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;small&gt;Note: This is not the right way to calculate the profit, but just an example to show how to refer to a measure in DAX&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: Measures are a model-level object.&lt;/p&gt;

&lt;p&gt;Although it is not recommended, but you can also precede a measure reference in a DAX formula with its table name.&lt;/p&gt;

&lt;h4&gt;
  
  
  example:
&lt;/h4&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="n"&gt;Revenue&lt;/span&gt; &lt;span class="p"&gt;=&lt;/span&gt; &lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Total&lt;/span&gt; &lt;span class="n"&gt;Sales&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt; &lt;span class="p"&gt;-&lt;/span&gt; &lt;span class="n"&gt;Sales&lt;/span&gt;&lt;span class="p"&gt;[&lt;/span&gt;&lt;span class="n"&gt;Total&lt;/span&gt; &lt;span class="n"&gt;Purchases&lt;/span&gt;&lt;span class="p"&gt;]&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--zJdhQ3_Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i7ebfaf4idnjftvtw219.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--zJdhQ3_Z--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/i7ebfaf4idnjftvtw219.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;/p&gt;

&lt;p&gt;As we mentioned earlier many reasons to precede the table name in column referring measure, another reason is to differentiate between column referring and measure referring formulas.&lt;/p&gt;

&lt;h2&gt;
  
  
  Summary:
&lt;/h2&gt;

&lt;ul&gt;
&lt;li&gt;You can refer a &lt;strong&gt;TABLE&lt;/strong&gt; in a DAX Formula &lt;code&gt;Sales Orders = Sales&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;You can refer a &lt;strong&gt;COLUMN&lt;/strong&gt; in a DAX Formula &lt;code&gt;Total Sales = SUM([Amount])&lt;/code&gt;
&lt;/li&gt;
&lt;li&gt;You can refer a &lt;strong&gt;MEASURE&lt;/strong&gt; in a DAX Formula 
&lt;code&gt;Revenue = [Total Sales] - [Total Purchases]&lt;/code&gt;
&lt;/li&gt;
&lt;/ul&gt;

</description>
      <category>powerbi</category>
      <category>dax</category>
      <category>dataanalysis</category>
    </item>
    <item>
      <title>Introduction to DAX</title>
      <dc:creator>Kevork Keheian</dc:creator>
      <pubDate>Sat, 01 Aug 2020 11:16:42 +0000</pubDate>
      <link>https://dev.to/kevorkkeheian/introduction-5ap8</link>
      <guid>https://dev.to/kevorkkeheian/introduction-5ap8</guid>
      <description>&lt;p&gt;DAX is mainly used to add calculations to the Power BI Model&lt;br&gt;
You can add 3 types of calculations:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;Calculated Tables&lt;/li&gt;
&lt;li&gt;Calculated Columns&lt;/li&gt;
&lt;li&gt;Measures&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;It can also be used to define RLS &lt;a href="https://docs.microsoft.com/en-us/power-bi/admin/service-admin-rls/"&gt;(Row-Level Security)&lt;/a&gt;&lt;/p&gt;



&lt;h2&gt;
  
  
  1 - Calculated Tables:
&lt;/h2&gt;

&lt;p&gt;Regarding the calculated tables, DAX is used to whether duplicate or transform an existing model data, create a series data or even produce a new table.&lt;br&gt;
Cons: It increases the model storage size =&amp;gt; could prolong the data refresh durations:&lt;br&gt;
&lt;strong&gt;Examples:&lt;/strong&gt; &lt;em&gt;Date tables, Role playing dimensions, what-if analysis, etc...&lt;/em&gt;&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note:&lt;/strong&gt; &lt;em&gt;Calculated table can't connect to external data. You need to use Power Query to do that.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;
&lt;h3&gt;
  
  
  a - Date Table:
&lt;/h3&gt;

&lt;p&gt;Date tables are mostly used for special filters as time intelligence.&lt;br&gt;
For example if you have a model with missing dates and you want to calculate the average per date and the calculation requires the missing dates (ex: holidays), you need to create a date table table with one to many relation to do an accurate calculation.&lt;br&gt;
EX: &lt;code&gt;CALENDAR&lt;/code&gt; and &lt;code&gt;CALENDARAUTO&lt;/code&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  b - Role-playing dimensions:
&lt;/h3&gt;

&lt;p&gt;The Date table can also be defined as role-playing dimension.&lt;br&gt;
This happens when table has two date fields that are related to Date column in Date Table.&lt;br&gt;
(EX: &lt;code&gt;[Sales].OrderedDate&lt;/code&gt; and &lt;code&gt;[Sales].DeliveredDate&lt;/code&gt; ----&amp;gt; &lt;code&gt;[DateTable].Date&lt;/code&gt;&lt;br&gt;
In this case the Date table's Date column is playing the role of Ordered Date and Delivered Date of Sales Table.&lt;/p&gt;

&lt;blockquote&gt;
&lt;p&gt;&lt;strong&gt;Note&lt;/strong&gt;: &lt;em&gt;Power BI models allow only one active relationship between tables.&lt;/em&gt;&lt;/p&gt;
&lt;/blockquote&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--2eA75Td_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6yduw6paznpjtni8avcx.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--2eA75Td_--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/6yduw6paznpjtni8avcx.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt;Source: &lt;a href="https://docs.microsoft.com/en-us/learn/modules/dax-power-bi-write-formulas/1-introduction"&gt;Microsoft Learn&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;

&lt;p&gt;So, if you create 2 relations between 2 tables in the Power BI model one of them will be active (solid line) and the other not (dotted line).&lt;br&gt;
But the only way you can use this inactive relation using &lt;code&gt;USERELATIONSHIP&lt;/code&gt; DAX function.&lt;br&gt;
Another way is to create 2 date tables.&lt;/p&gt;

&lt;p&gt;&lt;a href="https://res.cloudinary.com/practicaldev/image/fetch/s--gFfksKTP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tipoddzvy02h5ix64940.png" class="article-body-image-wrapper"&gt;&lt;img src="https://res.cloudinary.com/practicaldev/image/fetch/s--gFfksKTP--/c_limit%2Cf_auto%2Cfl_progressive%2Cq_auto%2Cw_880/https://dev-to-uploads.s3.amazonaws.com/i/tipoddzvy02h5ix64940.png" alt="Alt Text"&gt;&lt;/a&gt;&lt;br&gt;
&lt;small&gt;Source: &lt;a href="https://docs.microsoft.com/en-us/learn/modules/dax-power-bi-write-formulas/1-introduction"&gt;Microsoft Learn&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h3&gt;
  
  
  c - What-if analysis:
&lt;/h3&gt;

&lt;p&gt;What-if analysis is a featured supported in Power BI. It is a parameter that when created automatically adds a calculated table to the model.&lt;br&gt;
They allow selection of filter by value stored in the calculated tables.&lt;/p&gt;



&lt;h2&gt;
  
  
  2 - Calculated Columns:
&lt;/h2&gt;

&lt;p&gt;As we mentioned earlier, DAX can also be used to add calculated columns.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight csharp"&gt;&lt;code&gt;&lt;span class="c1"&gt;//This is not an actual DAX formula&lt;/span&gt;
&lt;span class="c1"&gt;//But it represents the concept&lt;/span&gt;
  &lt;span class="k"&gt;foreach&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;row&lt;/span&gt; &lt;span class="k"&gt;in&lt;/span&gt; &lt;span class="n"&gt;table&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="p"&gt;{&lt;/span&gt;
      &lt;span class="k"&gt;return&lt;/span&gt; &lt;span class="k"&gt;value&lt;/span&gt;&lt;span class="p"&gt;;&lt;/span&gt;
  &lt;span class="p"&gt;}&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;It only differs if the connection is Import or Direct Query. &lt;br&gt;
 When a calculated column is added to an Import storage  mode table, the calculated column is evaluated on refresh which increases the size of the model. But when added to a Direct Query storage mode the calculation is evaluated by the underlying source database upon querying the table.&lt;/p&gt;



&lt;h2&gt;
  
  
  3 - Measures:
&lt;/h2&gt;

&lt;p&gt;Finally, you can write DAX formulas to add measures. It is used to summarize the model data.&lt;/p&gt;

&lt;p&gt;For example: &lt;code&gt;Revenue = SUM(Sales[Sales Amount])&lt;/code&gt;&lt;/p&gt;

&lt;p&gt;Where Sales is the name of the table and Sales Amount is the name of the column that we are calculating.&lt;br&gt;
 Unlike calculated columns the returned value of a measure is never stored in the model and the formula is assessed at query time. So, the storage size of the model is affected.&lt;/p&gt;

</description>
      <category>powerbi</category>
      <category>dax</category>
      <category>dataanalysis</category>
    </item>
    <item>
      <title>Computational Thinking - Riddle 1</title>
      <dc:creator>Kevork Keheian</dc:creator>
      <pubDate>Thu, 11 Jun 2020 22:05:03 +0000</pubDate>
      <link>https://dev.to/kevorkkeheian/computational-thinking-riddle-1-37mf</link>
      <guid>https://dev.to/kevorkkeheian/computational-thinking-riddle-1-37mf</guid>
      <description>&lt;p&gt;What two whole, positive numbers that have a one-digit answer when multiplied and a two-digit answer when added?&lt;br&gt;
&lt;small&gt;riddle source: &lt;a href="http://riddles.com/"&gt;http://riddles.com/&lt;/a&gt;&lt;/small&gt;&lt;/p&gt;
&lt;h2&gt;
  
  
  How to?
&lt;/h2&gt;

&lt;p&gt;We need to declare 2 variable &lt;code&gt;sum&lt;/code&gt; and &lt;code&gt;mult&lt;/code&gt;:&lt;/p&gt;

&lt;ul&gt;
&lt;li&gt;
&lt;code&gt;sum&lt;/code&gt; is to check the &lt;strong&gt;sum&lt;/strong&gt; of the 2 digits.&lt;/li&gt;
&lt;li&gt;
&lt;code&gt;mult&lt;/code&gt; is to check the &lt;strong&gt;multiplication&lt;/strong&gt; of the 1 digit.&lt;/li&gt;
&lt;/ul&gt;

&lt;p&gt;And both should be assigned as 0.&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="nb"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;span class="n"&gt;mult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="mi"&gt;0&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;Now we need 2 for loops to iterate through the needed numbers&lt;br&gt;
The numbers should be between 1 and 9, beacuse their multiplication should be only 1 digit.&lt;br&gt;
1-Any number multiplied by 0 will result 0&lt;/p&gt;

&lt;p&gt;2-Any number less than 10 multiplied by 10 or a number greater than 10 will result to number of 2 digits&lt;br&gt;
&lt;/p&gt;

&lt;div class="highlight"&gt;&lt;pre class="highlight python"&gt;&lt;code&gt;&lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
    &lt;span class="k"&gt;for&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt; &lt;span class="ow"&gt;in&lt;/span&gt; &lt;span class="nb"&gt;range&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="mi"&gt;1&lt;/span&gt;&lt;span class="p"&gt;,&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
        &lt;span class="nb"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;
        &lt;span class="n"&gt;mult&lt;/span&gt; &lt;span class="o"&gt;=&lt;/span&gt; &lt;span class="n"&gt;x&lt;/span&gt; &lt;span class="o"&gt;*&lt;/span&gt; &lt;span class="n"&gt;y&lt;/span&gt;
        &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;sum&lt;/span&gt; &lt;span class="o"&gt;&amp;gt;=&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
            &lt;span class="k"&gt;if&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;mult&lt;/span&gt; &lt;span class="o"&gt;&amp;lt;&lt;/span&gt; &lt;span class="mi"&gt;10&lt;/span&gt;&lt;span class="p"&gt;):&lt;/span&gt;
                &lt;span class="k"&gt;print&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;x&lt;/span&gt;&lt;span class="p"&gt;)&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="s"&gt;" and "&lt;/span&gt; &lt;span class="o"&gt;+&lt;/span&gt; &lt;span class="nb"&gt;str&lt;/span&gt;&lt;span class="p"&gt;(&lt;/span&gt;&lt;span class="n"&gt;y&lt;/span&gt;&lt;span class="p"&gt;))&lt;/span&gt;
        &lt;span class="k"&gt;break&lt;/span&gt;
&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



&lt;p&gt;And finally we need to break the iteration at the end of the second loop to avoid iterating through the same numbers twice.&lt;/p&gt;

&lt;h2&gt;
  
  
  Answer
&lt;/h2&gt;



&lt;div class="highlight"&gt;&lt;pre class="highlight console"&gt;&lt;code&gt;&lt;span class="go"&gt;
&lt;/span&gt;&lt;span class="gp"&gt; &amp;gt;&lt;/span&gt;&lt;span class="w"&gt; &lt;/span&gt;9 and 1
&lt;span class="go"&gt;
&lt;/span&gt;&lt;/code&gt;&lt;/pre&gt;&lt;/div&gt;



</description>
      <category>python</category>
      <category>computationalthinking</category>
      <category>riddle</category>
    </item>
    <item>
      <title>How to accelerate your Computational Thinking</title>
      <dc:creator>Kevork Keheian</dc:creator>
      <pubDate>Thu, 11 Jun 2020 21:50:17 +0000</pubDate>
      <link>https://dev.to/codgram/how-to-accelerate-your-computational-thinking-45k8</link>
      <guid>https://dev.to/codgram/how-to-accelerate-your-computational-thinking-45k8</guid>
      <description>&lt;p&gt;Computational thinking is the practice of systematically solving a problem and of constructing and presenting a solution in such a manner that a machine can execute it. Yet to think like a computer scientist, does not require an IT background.&lt;br&gt;
Accelaratig your computational thinking just needs some (and sometimes a lot) of practice.&lt;br&gt;
In this coming weeks I will be posting riddles, most of it mathematical riddles, and how to solve them by writing a few lines of code.&lt;/p&gt;

</description>
      <category>python</category>
      <category>computationalthinking</category>
      <category>riddle</category>
    </item>
  </channel>
</rss>
