AI知识库 @ai521
326 subscribers
22.1K photos
42 videos
19 files
850 links
@ai521 专注分享最实用的AI内容

🤖 AI教程(新手到进阶)
🧠 AI知识科普(大模型 / 提示词 / 自动化)
📰 AI资讯更新(每日最新AI动态)
📚 AI实战技巧(写作 / 绘画 / 编程 / 赚钱)
🔧 最新AI工具推荐

每天更新AI干货
长期做一个真正有价值的AI频道
Download Telegram
Explaining Lineage in DAX

In DAX, lineage is an important concept, and it is vital to understand how to work with and manipulate it. As I did in past articles, I will use DAX queries to explain this concept and its effects. I start with a simple query to get the order count for the product of the brand “Adventure Works”: EVALUATE CALCULATETABLE( SUMMARIZECOLUMNS('Date'[Year] ,'Date'[MonthShortName] ,'Date'[MonthKey] ,'Product'[ProductCategoryName] ,"Order Count", [Online Order Count] ) ,'Product'[BrandName] = "Adventure Works" ) ORDER BY 'Date'[MonthKey] ,'Product'[ProductCategoryName] This is an extract of the result from the query: This query returns 180 rows. Keep it in mind, as it will be important later on. Next, I will introduce a filter for a specific month and show the lineage’s role
. I will add a filter for April 2026: DEFINE VAR YearMonthFilter = 202604 EVALUATE CALCULATETABLE( SUMMARIZECOLUMNS('Date'[Year] ,'Date'[MonthShortName] ,'Date'[MonthKey] ,'Product'[ProductCategoryName] ,"Order Count", [Online Order Count] ) ,'Product'[BrandName] = "Adventure Works" ,'Date'[MonthKey] = YearMonthFilter ) ORDER BY 'Date'[MonthKey] ,'Product'[ProductCategoryName] In this case, I define a variable and set the value to 202604. Next, I add it as a filter to the CALCULATETABLE() function. Nothing special so far. In this case, the lineage is not important, as a scalar value sets the filter. But we can set a lineage by using the TREATAS() function: DEFINE VAR YearMonthFilter = TREATAS({ 202604 }, 'Date'[MonthKey]) EVALUATE CALCULATETABLE( SUMMARIZECOLUMNS('Date'[Year] ,'Date'[MonthShortName] ,'Date'[MonthKey] ,'Product'[ProductCategoryName] ,"Order Count", [Online Order Count] ) ,'Product'[BrandName] = "Adventure Works" ,YearMonthFilter ) ORDER BY 'Date'[MonthKey] ,'Product'[ProductCategoryName] As you can see, the introduction of TREATAS() allows us to pass the variable as a filter. CALCULATETABLE() uses the lineage set by TREATAS() as a filter on the column ‘Date'[MonthKey]. The result doesn’t change, but the query is simpler, as I don’t need to pass the condition as “column equals the filter-value”. In fact, Power BI uses this form all the time when it passes filters set in a report to the semantic model. But it does differently: It defines variables, sets the lineage and adds all filters directly to SUMMARIZECOLUMNS() : DEFINE VAR YearMonthFilter = TREATAS({ 202604 }, 'Date'[MonthKey]) VAR SelectedBrand = TREATAS( { "Adventure Works" }, 'Product'[BrandName]) EVALUATE SUMMARIZECOLUMNS('Date'[Year] ,'Date'[MonthShortName] ,'Date'[MonthKey] ,'Product'[ProductCategoryName] ,YearMonthFilter ,SelectedBrand ,"Order Count", [Online Order Count] ) ORDER BY 'Date'[MonthKey] ,'Product'[ProductCategoryName] Clearing the lineage You might encounter situations where you need to clear the lineage. The method for doing it varies depending on whether you have a single or multiple values as a filter. For example, look at the following code, where I use VALUE() to remove the lineage on the previous expression: DEFINE VAR YearMonthFilter = TREATAS({ 202604 }, 'Date'[MonthKey]) VAR YearMonthFilter_cleared = VALUE(YearMonthFilter) EVALUATE CALCULATETABLE( SUMMARIZECOLUMNS('Date'[Year] ,'Date'[MonthShortName] ,'Date'[MonthKey] ,'Product'[ProductCategoryName] ,"Order Count", [Online Order Count] ) ,'Product'[BrandName] = "Adventure Works" ,YearMonthFilter_cleared ) ORDER BY 'Date'[MonthKey] ,'Product'[ProductCategoryName] This is the error delivered by Power BI: The engine cannot work with the filter in line 71 because it no longer has lineage. It will work in this form: DEFINE VAR YearMonthFilter = TREATAS({ 202604 }, 'Date'[MonthKey]) VAR YearMonthFilter_cleared = VALUE(YearMonthFilter) EVALUATE CALCULATETABLE( SUMMARIZECOLUMNS('Date'[Year] ,'Date'[MonthShortName] ,'Date'[MonthKey] ,'Product'[ProductCategoryName] ,"Order Count", [Online Order Count] ) ,'Product'[BrandName] = "Adventure Works" ,'Date'[MonthKey] = YearMonthFilter_cleared ) ORDER BY 'Date'[MonthKey] ,'Product'[ProductCategoryName] As you can see here, the query returns the same result as before: Notice the change of the filter argument in line 91. But there is a simpler way of clearing the lineage when working with measures. Look at the following query with the Measure [Order Count
full year], which calculates the order count for the entire year: DEFINE MEASURE 'All Measures'[Order Count full year] = VAR SelYear = TREATAS({ SELECTEDVALUE('Date'[Year]) }, 'Date'[Year]) RETURN CALCULATE([Online Order Count] ,REMOVEFILTERS('Date') ,SelYear ) EVALUATE CALCULATETABLE( SUMMARIZECOLUMNS('Date'[Year] ,'Date'[MonthShortName] ,'Date'[MonthKey] ,'Product'[ProductCategoryName] ,"Order Count", [Online Order Count] ,"Order Count full year", [Order Count full year] ) ,'Product'[BrandName] = "Adventure Works" ) ORDER BY 'Date'[MonthKey] ,'Product'[ProductCategoryName] This is an extract of the result: Now I add a scalar value to the variable: DEFINE MEASURE 'All Measures'[Order Count full year] = VAR SelYear = TREATAS({ SELECTEDVALUE('Date'[Year]) }, 'Date'[Year]) VAR SelYear_Plus1 = SelYear + 0 RETURN CALCULATE([Online Order Count] ,REMOVEFILTERS('Date') ) EVALUATE CALCULATETABLE( SUMMARIZECOLUMNS('Date'[Year] ,'Date'[MonthShortName] ,'Date'[MonthKey] ,'Product'[ProductCategoryName] ,"Order Count", [Online Order Count] ,"Order Count full year", [Order Count full year] ) ,'Product'[BrandName] = "Adventure Works" ) ORDER BY 'Date'[MonthKey] ,'Product'[ProductCategoryName] This operation clears the lineage, and the measure no longer works: What I can still do is use an equal filter to get the previous result: DEFINE MEASURE 'All Measures'[Order Count full year] = VAR SelYear = TREATAS({ SELECTEDVALUE('Date'[Year]) }, 'Date'[Year]) VAR SelYear_Plus1 = SelYear + 0 RETURN CALCULATE([Online Order Count] ,REMOVEFILTERS('Date') ,'Date'[Year] = SelYear_Plus1 ) EVALUATE CALCULATETABLE( SUMMARIZECOLUMNS('Date'[Year] ,'Date'[MonthShortName] ,'Date'[MonthKey] ,'Product'[ProductCategoryName] ,"Order Count", [Online Order Count] ,"Order Count full year", [Order Count full year] ) ,'Product'[BrandName] = "Adventure Works" ) ORDER BY 'Date'[MonthKey] ,'Product'[ProductCategoryName] Now I get the same result as before: And now, let’s use multiple values as a filter. For example, two months: DEFINE VAR YearMonthFilter = TREATAS({ 202604, 202605 }, 'Date'[MonthKey]) EVALUATE CALCULATETABLE( SUMMARIZECOLUMNS('Date'[Year] ,'Date'[MonthShortName] ,'Date'[MonthKey] ,'Product'[ProductCategoryName] ,"Order Count", [Online Order Count] ) ,'Product'[BrandName] = "Adventure Works" ,YearMonthFilter ) ORDER BY 'Date'[MonthKey] ,'Product'[ProductCategoryName] Here is the result of this query: One way to remove the lineage of a variable with multiple values is to use SUMMARIZECOLUMNS() : DEFINE VAR YearMonthFilter = TREATAS({ 202604, 202605 }, 'Date'[MonthKey]) VAR YearMonthFilter_cleared = SUMMARIZECOLUMNS(YearMonthFilter) EVALUATE CALCULATETABLE( SUMMARIZECOLUMNS('Date'[Year] ,'Date'[MonthShortName] ,'Date'[MonthKey] ,'Product'[ProductCategoryName] ,"Order Count", [Online Order Count] ) ,'Product'[BrandName] = "Adventure Works" ,YearMonthFilter_cleared ) ORDER BY 'Date'[MonthKey] ,'Product'[ProductCategoryName] Unfortunately, this method removes the filter altogether, and all months are returned in 180 rows (The same number of rows as with the initial query): Technically, the lineage is not cleared because the query still works, but the month filter is removed. But when you try using the variable “YearMonthFilter_cleared” with an IN operator, it doesn’t work anymore: In this context, I tried other functions, like DISTINCT() and VALUES() . While DISTINCT() had no effect, VALUES() has. For example, while this query doesn’t work: DEFINE VAR YearMonthFilter =
TREATAS({ 202604, 202605 }, 'Date'[MonthKey]) VAR YearMonthFilter_cleared = VALUES(YearMonthFilter) EVALUATE CALCULATETABLE( SUMMARIZECOLUMNS('Date'[Year] ,'Date'[MonthShortName] ,'Date'[MonthKey] ,'Product'[ProductCategoryName] ,"Order Count", [Online Order Count] ) ,'Product'[BrandName] = "Adventure Works" ,YearMonthFilter_cleared ) ORDER BY 'Date'[MonthKey] ,'Product'[ProductCategoryName] Here is the error message: This works when using an IN operator, which indicates that the lineage is cleared when using VALUES(): DEFINE VAR YearMonthFilter = TREATAS({ 202604, 202605 }, 'Date'[MonthKey]) VAR YearMonthFilter_cleared = VALUES(YearMonthFilter) EVALUATE CALCULATETABLE( SUMMARIZECOLUMNS('Date'[Year] ,'Date'[MonthShortName] ,'Date'[MonthKey] ,'Product'[ProductCategoryName] ,"Order Count", [Online Order Count] ) ,'Product'[BrandName] = "Adventure Works" ,'Date'[MonthKey] IN YearMonthFilter ) ORDER BY 'Date'[MonthKey] ,'Product'[ProductCategoryName] Here is the result of the query: The documentation for VALUES() states that this function requires a table or column reference. But this behaviour shows that it depends on how the variable is used in the query. As the variable has a lineage set, VALUES() accept it as a column reference. Next, let’s change how we apply a filter by manipulating the lineage. I want to create a report showing all online orders by country, along with the orders served by stores in each country. For example, I have 68 customer orders from Germany in April 2026. I want to see how many orders have been served by stores in that country, if any. Something like this: I can do it by working with a variable: DEFINE MEASURE 'All Measures'[Orders served from Country] = VAR SelCountry = SELECTEDVALUE('Customer'[RegionCountryName]) RETURN CALCULATE([Online Order Count] ,REMOVEFILTERS(Customer[RegionCountryName]) ,'Store'[RegionCountryName] = SelCountry ) EVALUATE CALCULATETABLE( SUMMARIZECOLUMNS('Date'[Year] ,'Date'[Month] ,'Date'[MonthKey] ,'Customer'[RegionCountryName] ,"Order Count", [Online Order Count] ,"Order Count Country Check", [Order Count Country Check] ) ,'Product'[BrandName] = "Adventure Works" ) ORDER BY 'Date'[Year] ,'Date'[Month] ,'Customer'[RegionCountryName] In this approach, I store the current country in a variable. Then I remove the filter from Customer[RegionCountryName]. And I replace it with a filter on ‘Store'[RegionCountryName]. Or I can do it in this way by using TREATAS(): DEFINE MEASURE 'All Measures'[Orders served from Country] = CALCULATE([Online Order Count] ,REMOVEFILTERS(Customer[RegionCountryName]) ,TREATAS(VALUES('Customer'[RegionCountryName]) ,'Store'[RegionCountryName]) ) EVALUATE CALCULATETABLE( SUMMARIZECOLUMNS('Date'[Year] ,'Date'[Month] ,'Date'[MonthKey] ,'Customer'[RegionCountryName] ,"Order Count", [Online Order Count] ,"Orders served from Country", [Orders served from Country] ) ,'Product'[BrandName] = "Adventure Works" ) ORDER BY 'Date'[Year] ,'Date'[Month] ,'Customer'[RegionCountryName] In this approach, I again remove the filter from Customer[RegionCountryName]. But then I use TREATAS() to switch the filter lineage for the current country to ‘Store'[RegionCountryName]. In this approach, I don’t need a variable; I can directly filter the store table by the current country. This code is much shorter but can be harder to understand for readers who don’t know how TREATAS() works. Since we can create ad hoc tables in DAX, we might run into issues because those tables lack lineage. I
can start writing code about this, but SQLBI already did this, and you can read their article, which is very well explained: You can find it here: The concept of lineage can be hard to understand, even though we use it all the time when working with filters in DAX. Power BI generates code using TREATAS() all the time when it applies report filters. And sometimes it can lead to simpler DAX code when you know how to manipulate it efficiently. This can become vital when I create a table with DAX from existing tables. The table will retain the lineage. This can lead to issues when I try to add relationships to the source tables. Without clearing the lineage, I will encounter an error due to a circular dependency. I encourage you to start experimenting with the concepts shown here and to try to optimise your DAX code. Although “optimise” is the wrong word, as I didn’t notice any performance improvements when using the variants shown. But having DAX code which is shorter and easier to read can be an optimisation by itself. Have fun working with it. A SQLBI article about working with lineage: Like in my previous articles, I use the Contoso sample dataset. You can download the ContosoRetailDW Dataset for free from Microsoft here . The Contoso Data can be used freely under the MIT License, as described in this document . I changed the dataset to shift the data to contemporary dates.
技术保证基金免费开放AI专利分析数据- 阿视亚经济

技术保证基金29日表示,将通过行政安全部公共数据门户,以开放型应用程序编程接口(API)形式免费提供135万件基于人工智能(AI)的专利分析数据。 为支持中小·创投企业的技术创新和AI应用,技术保证基金与行政安全部、知识产权厅、科学技术信息通信部、中小风险企业部合作,将通过企业持有专利分析得出的技
David Sacks's 11th-Hour Plea Led to Trump's Backtrack on AI Executive Order

President Trump postponed signing an order on the dangers posed by artificial intelligence after an adviser warned that industry guardrails could slow down U.S. models in the race against tools from China.
Expertise in the Age of AI

Does it make sense to hire junior engineers in the age of coding agents? Junior engineers are expensive, both in salary and seniors engineers’ time. This cost was partially recouped through code contributions, but today, it’s more effective to directly maximize the output of your senior engineers. The hiring market reflects this trend: senior engineers have an easy time finding jobs, while fresh CS grads are having their worst years ever. And yet, OpenAI, Anthropic, and many top companies continue to compete fiercely for junior talent. What’s going on? In this essay, I’ll explore the changing nature of expertise in the age of AI. I think it helps to think about the impact of AI in terms of math, which had its AI moment half a century ago. There used to be a job called “calculator”, which was a human who could do math calculations accurately and quickly.
These people balanced books, calculated artillery firing angles based on distance and wind adjustments, calculated optimal hull shapes for ships and aircraft bodies, and so on. This job doesn’t exist anymore, and the last serious use of abaci and slide rules was in the 1970s, due to the invention of the scientific calculator. Calculators have only become more sophisticated over time, with today’s numerical modeling software running full scale physics and engineering simulations. (For the purpose of this essay, I’ll use “calculator” to mean everything from basic calculators to modeling software.) Despite the existence of calculators, we teach and expect people to learn algebra, geometry, and calculus in high school. Continuing into the college level, we expect STEM majors to learn multivariable calculus, ODEs, PDEs, statistics, and linear algebra. Upon graduation, the vast majority of them use calculators every day and forget how to do all but the most basic mental math. There are two basic explanations for this discrepancy: As a formerly strong believer of the signaling hypothesis, I am now increasingly buying the skills hypothesis (let’s say ~50% attribution to each cause). It’s clear that senior engineers today are far more capable of using coding agents than their junior counterparts, and a large portion of this is due to having struggled through 5+ years of writing code manually. Currently, the level of computing intuition needed to additively prompt the coding agents sits at roughly 5 years’ experience level. Today’s seniors were lucky enough to get paid to build their computing intuition, but the gap grows as coding agents continue to improve. In between coding agent improvements and natural variation in learning aptitude, maybe 50% of new CS graduates will not be able to catch up, ever. Some senior engineers will also eventually fall behind the curve despite their head start. To answer the opening question of the essay: only some junior engineers are worth hiring, specifically, the ones who are good enough to reach some useful threshold of “coding intuition” within ~2-3 years of having graduated. Since there are not very many of these graduates, a small number of elite companies compete fiercely for this talent. The second-class tier of software consultants will continue growing, expanding the total size of the job market, but I don’t anticipate that their salaries will grow anywhere close to as rapidly as today’s senior engineers. Even as the bar to get into software engineering rises, I still think everyone should learn some coding. Too often, I see people treat computers as appliances - capable of doing what they were built to do, but nothing more. If you don’t think of computers as scriptable or programmable, then you won’t ever think to ask AI to automate something for you! The same is also true for many other fields, too! Math, law, taxes, medicine, DIY home repair, etc… Abundant and cheap expertise is now available for just $20/month, if only you know how to ask. I would say that the major unlocks are at: If you’re already a software engineer, you might consider dabbling in data science, frontend, backend, security, and performance optimization/profiling – all of which are distinct skillsets. Here’s a data science example of a “how + when + correctness”: A coworker was running some correlational analysis on a dataset and found it difficult to understand what was going on. I suggested he literally ask Claude to “make it
prettier using NMF ” – and all of a sudden, useful clusters started appearing. (The expanded version of this prompt: NMF on the pairwise distance matrix gives k cluster centroids and cluster membership scores. Reordering the original distance matrix according to argmax(cluster score) highlights the clusters. The “how” here is knowing the keyword “NMF”; the “when” is “clustering on distance matrices”, and the “correctness” is knowing the preconditions for using it.) Do your homework! One weirdly common and nihilistic take on AI is that you should stop trying so hard, and just use AI to speedrun your classes. I think this is probably the worst possible response. Doing the work is the best way to build mastery, and just like you weren’t allowed to use a calculator on your middle school math classes, you should hold off on using AI to do your classwork. The calculator advice sounded condescending when I was a kid, and this AI advice probably sounds the same – but I really do believe it’s for your own good. This advice continues to hold after you graduate, too. Don’t use AI until you’ve done it by hand at least once.
Show HN: I built an AI medical-records hub after my mom's cancer diagnosis

4 questions · 2 ready Will the platelet drop change cycle 4? Imaging timeline after this round? Add anti-nausea before next infusion? Pneumonia vaccine timing? Before the appointment KeptWell reads your recent labs, medications, and notes — then drafts the questions you'd regret not asking. Add your own. Print the list.
Please Use AI

Shawn Smucker May 04, 2026 9,311 261 2,356 Share Be sure to use AI when making your next, I don’t know, meal plan, for example. Definitely do not call your friend who loves to cook and ask her for her favorite recipes or tips or ways to save time making meals, because you will end up talking for longer than you had hoped, hearing, perhaps, about her father’s cancer diagnosis or how lonely she’s been or even what she’s planted in her spring garden and then lost with the early frost. And be sure to use AI when your next child gets married, so that you can write them the perfect toast or poem or speech or song because no one wants to hear your words, the actual poorly written words of a parent (you) who changed hundreds of diapers for said child or fed them in the middle of the night from your actual body. Or cried when they were late home because you were positive the
y were dead. We don't want those words—we’d prefer the sterile words of a machine that never lived, never had an original thought, never felt the pain of miscarriage or broken relationships or the joy of a friendship restored or of seeing spring’s first robin dancing on frost. And be sure to use AI when working on your next book or essay or piece of art or photography, and then smile or even laugh at your own cleverness when you see how good it is, and how easy, because who the hell has time to work at something, to give time to craft, to create with their own minds, to spend years being mediocre. Why do that when mastery, or at least competency is so simple only a good prompt away? and while you do I’ll be over here in my 50th year, my youngest daughter asleep on my chest, my arm falling asleep because I dare not move lest I scare away this moment, lying here melancholy about my older children moving out and my middle children no longer needing me, at least not like they used to, weary about this body that fails me now in ever increasing ways that will never be restored. Sighing over stories I tried to write but never hit the page the way they felt in my mind. But isn’t that, my flesh-and-blood friend, the natural order of things? the longing for something that could always be a bit better or the way that anything worth doing feels a bit clumsy and painful, especially at first or hearing another human voice and somehow realizing the beauty of life is found in all of these subtle imperfections The Courage to Live It is a reader-supported publication. To receive new posts and support my work, consider becoming a free or paid subscriber.